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

Nick Sabalausky a at a.a
Mon May 11 13:03:39 PDT 2009


"Steven Schveighoffer" <schveiguy at yahoo.com> wrote in message 
news:op.utrtl8x7eav7ka at steves.networkengines.com...
> On Mon, 11 May 2009 09:37:56 -0400, Georg Wrede <georg.wrede at iki.fi> 
> wrote:
>
>> Steven Schveighoffer wrote:
>>> For example:
>>>  mydic[x] = mydic[y] = mydic[z] = mydic.length;
>>
>>
>> I distinctly remember Walter discouraging chained assignments in the 
>> doccs, already in the very early versions of D.
>
> Seriously?  So the correct method is to do this:
>
> auto tmp = mydic.length;
> mydic[x] = tmp;
> mydic[y] = tmp;
> mydic[z] = tmp;
>
> ???
>
> That sucks.  We have to remember, there are reasons why we stopped having 
> to use assembly :)
>

I was giving a little bit of thought to assignment chaining the other day. 
Unless someone can point out why I'm wrong, I think some of the 
functional-style stuff we've been getting into can make assignment chaining 
obsolete.

Hypothetical example:
[mydic[x], mydic[y], mydic[z]].fill(mydic.length);

I think something like that would be more clear than both the "tmp" and 
assignment chaining versions, and perhaps allow any language complexities 
that arise from the assignment chaining feature to be removed. 





More information about the Digitalmars-d mailing list