D and expression evaluation order.

Bruno Medeiros brunodomedeiros+spam at com.gmail
Sun May 6 06:31:24 PDT 2007


Manfred Nowak wrote:
> Bruno Medeiros wrote
>> All operands are evaluated left to right, with the exception of
>> the assignment operators which are evaluated right-to-left.
> [...]
>> Any problem with this one?
> 
> Don't you see a reason why Walter has tossed himself out of this
> thread?
> 
> Given an expression `a op b'
> |  The expression is rewritten as both:
> |    a.opfunc(b)
> |    b.opfunc_r(a)
> 
> This is from the specs! Now what is the evaluation order of `a op b'?
> `a' then `b'?
> `b' then `a'?
> 
> If there is a cloud some people only see the silver lining.
> 
> -manfred 

Hum, good point. This looks like an unprecedented case, I don't know if 
any other languages have reverse operator overloading like D. In any 
case a design decision would have to be made (thus creating a new 
evaluation rule).
I would say that the order should be 'a' then 'b', because this way the 
programmer doesn't have to check which operator function is being 
invoked to know the evaluation order of such expression. This makes the 
code less dependent, which is particularly important since the 
underlying operator function could change in time, (from a non-reverse, 
to a reverse one, for example), and it would be best to maintain the 
original order semantics.

-- 
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list