assignment: left-to-right or right-to-left evaluation?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon May 11 09:33:00 PDT 2009


Georg Wrede wrote:
> If the programmer has introduced dependencies on the evaluation order, 
> yes. But if he hasn't, then it will not introduce anything.

If violations could be checked such that invalid code is rejected, your 
solution would work.

> With
> 
>   a[fun] = gun;
> 
> a rewrite
> 
>   auto f = a[fun];
>   a[f] = gun;
> 
> makes it explicit how the programmer wants it done. It also removes any 
> uncertainty (and need to remember an arbitrary rule) for other people.
> 
> If you'd really want things easy for Walter, unambiguous, and clear for 
> the reader, then you'd advocate forbidding expressions in lvalues.

I think that would be too restrictive. a[b] is already an expression.

The solution is simple: define an order of evaluation such that even bad 
code behaves consistently.


Andrei



More information about the Digitalmars-d mailing list