digitalmars.D - minimal evaluation
- Qian Xu (17/17) Apr 06 2009 Hi All,
- Qian Xu (2/9) Apr 06 2009 Update: If minimal evaluation is not always enabled, and foo.getBar is N...
- davidl (5/15) Apr 06 2009 huh? post the whole code plz. It should work.
- downs (4/27) Apr 06 2009 Short-circuit evaluation is always enabled.
- Daniel Keep (4/34) Apr 06 2009 You beat me to it, AND you found it in the spec.
- downs (4/41) Apr 06 2009 Ooh a cookie!
- TomD (5/22) Apr 06 2009 Make it return true then. An "or" is true when it hits the first
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> дµÀ:huh? post the whole code plz. It should work. -- ʹÓà Opera ¸ïÃüÐԵĵç×ÓÓʼþ¿Í»§³ÌÐò: http://www.opera.com/mail/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
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. --QianShort-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:You beat me to it, AND you found it in the spec. ?cookie downs -- DanielHi 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. --QianShort-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
Daniel Keep wrote:downs wrote:Ooh a cookie! :D :munch:Qian Xu wrote:You beat me to it, AND you found it in the spec. ?cookie downsHi 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. --QianShort-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."-- 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.Make it return true then. An "or" is true when it hits the first true expression. Ciao TomD
Apr 06 2009
TomD wrote:Qian Xu Wrote:.. Wait. Did I just read that right - when an argument is null, isNull returns *false*? What the hell?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.Make it return true then. An "or" is true when it hits the first true expression.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