minimal evalu-OMG COOKIE YAY

downs default_357-line at yahoo.de
Mon Apr 6 08:25:37 PDT 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
>> 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

Ooh a cookie!

:D

:munch:

> 
>   -- Daniel



More information about the Digitalmars-d mailing list