digitalmars.D - minimal evaluation
- Qian Xu <quian.xu stud.tu-ilmenau.de> Apr 06 2009
- Qian Xu <quian.xu stud.tu-ilmenau.de> Apr 06 2009
- davidl <davidl nospam.org> Apr 06 2009
- downs <default_357-line yahoo.de> Apr 06 2009
- Daniel Keep <daniel.keep.lists gmail.com> Apr 06 2009
- downs <default_357-line yahoo.de> Apr 06 2009
- TomD <t_demmer nospam.web.de> Apr 06 2009
- downs <default_357-line yahoo.de> Apr 07 2009
- TomD <t_demmer nospam.web.de> Apr 07 2009
Hi All,
Is minimal evaluation always enabled in D?
I want to write a function IsNull(), so that I can check the precondition as
follows:
 if (isNull(foo) ||
   isNull(foo.getBar) ||
   isNull(foo.getBar.getBar2)
 {
  return false;
 }
 // normal code goes here
If an argument is null, the IsNull() will return false. Internally it will
be logged to console as well.
But I am not sure, if dmd-compiler generates code without minimal evaluation
in some cases. If minimal evaluation is not always enabled. I cannot do
precodition check in my way.
--Qian
Apr 06 2009
if (isNull(foo) || isNull(foo.getBar) || isNull(foo.getBar.getBar2) { return false; }
Update: If minimal evaluation is not always enabled, and foo.getBar is NULL. I will get a segfault when evaluating foo.getBar.getBar2.
Apr 06 2009
ÔÚ Mon, 06 Apr 2009 19:33:31 +0800£¬Qian Xu <quian.xu stud.tu-ilmenau.de> дµÀ:if (isNull(foo) || isNull(foo.getBar) || isNull(foo.getBar.getBar2) { return false; }
Update: If minimal evaluation is not always enabled, and foo.getBar is NULL. I will get a segfault when evaluating foo.getBar.getBar2.
huh? post the whole code plz. It should work. -- ʹÓà Opera ¸ïÃüÐԵĵç×ÓÓʼþ¿Í»§³ÌÐò: http://www.opera.com/mail/
Apr 06 2009
Qian Xu wrote:Hi All, Is minimal evaluation always enabled in D? I want to write a function IsNull(), so that I can check the precondition as follows: if (isNull(foo) || isNull(foo.getBar) || isNull(foo.getBar.getBar2) { return false; } // normal code goes here If an argument is null, the IsNull() will return false. Internally it will be logged to console as well. But I am not sure, if dmd-compiler generates code without minimal evaluation in some cases. If minimal evaluation is not always enabled. I cannot do precodition check in my way. --Qian
Short-circuit evaluation is always enabled. http://digitalmars.com/d/1.0/expression.html#OrOrExpression "If the left operand, converted to type bool, evaluates to true, then the right operand is not evaluated."
Apr 06 2009
downs wrote:Qian Xu wrote:Hi All, Is minimal evaluation always enabled in D? I want to write a function IsNull(), so that I can check the precondition as follows: if (isNull(foo) || isNull(foo.getBar) || isNull(foo.getBar.getBar2) { return false; } // normal code goes here If an argument is null, the IsNull() will return false. Internally it will be logged to console as well. But I am not sure, if dmd-compiler generates code without minimal evaluation in some cases. If minimal evaluation is not always enabled. I cannot do precodition check in my way. --Qian
Short-circuit evaluation is always enabled. http://digitalmars.com/d/1.0/expression.html#OrOrExpression "If the left operand, converted to type bool, evaluates to true, then the right operand is not evaluated."
You beat me to it, AND you found it in the spec. ?cookie downs -- Daniel
Apr 06 2009
Daniel Keep wrote:downs wrote:Qian Xu wrote:Hi All, Is minimal evaluation always enabled in D? I want to write a function IsNull(), so that I can check the precondition as follows: if (isNull(foo) || isNull(foo.getBar) || isNull(foo.getBar.getBar2) { return false; } // normal code goes here If an argument is null, the IsNull() will return false. Internally it will be logged to console as well. But I am not sure, if dmd-compiler generates code without minimal evaluation in some cases. If minimal evaluation is not always enabled. I cannot do precodition check in my way. --Qian
http://digitalmars.com/d/1.0/expression.html#OrOrExpression "If the left operand, converted to type bool, evaluates to true, then the right operand is not evaluated."
You beat me to it, AND you found it in the spec. ?cookie downs
Ooh a cookie! :D :munch:-- Daniel
Apr 06 2009
Qian Xu Wrote:Hi All, Is minimal evaluation always enabled in D? I want to write a function IsNull(), so that I can check the precondition as follows: Â if (isNull(foo) || Â Â Â isNull(foo.getBar) || Â Â Â isNull(foo.getBar.getBar2) Â { Â Â return false; Â } Â // normal code goes here If an argument is null, the IsNull() will return false. Internally it will be logged to console as well.
true expression. Ciao TomD
Apr 06 2009
TomD wrote:Qian Xu Wrote:Hi All, Is minimal evaluation always enabled in D? I want to write a function IsNull(), so that I can check the precondition as follows: Â if (isNull(foo) || Â Â Â isNull(foo.getBar) || Â Â Â isNull(foo.getBar.getBar2) Â { Â Â return false; Â } Â // normal code goes here If an argument is null, the IsNull() will return false. Internally it will be logged to console as well.
true expression.
.. Wait. Did I just read that right - when an argument is null, isNull returns *false*? What the hell?Ciao TomD
Apr 07 2009
downs Wrote: [...].. Wait. Did I just read that right - when an argument is null, isNull returns *false*? What the hell?
At least that is what he had written. Seems to be a case of "double negation is still a negation", an idiom quite common here in Bavaria. Not in programming, though. :-) Ciao TomD
Apr 07 2009









davidl <davidl nospam.org> 