Indexing access for Lists and Maps considered harmful?
Bruce Chapman
brucechapman at paradise.net.nz
Tue Jun 23 03:03:30 PDT 2009
Talden wrote:
>> ... We can have that if the construct is defined by
>> translation as:
>>
>> var tmp = "c";
>> map.put("b", tmp);
>> tmp
>>
>
> This is my preference too...
>
> m[a] = n[a] = x; // where m and n are maps.
>
> becomes
>
> X t = x;
> m.put(a, t); n.put(a, t);
> t;
>
Not quite! because assignment is right associative - therfore
m[a] = n[a] = x;
happens in the same order as
m[a] = (n[a] = x);
and therefore your translation should be
becomes
X t = x;
n.put(a, t);
m.put(a, t);
t;
The difference could be detected for example when n and m were both references to the same LinkedHashMap and the keys were different therefore the order of iteration would reflect the order of assignment.
Bruce
> Does semantically treating all multi-assignments this way break existing code?
>
> a = b = c;
>
> C t = c;
> a = t; b = t;
> t;
>
> Are there ways to get other side-effects in the current grammar? If
> not, defining it this way makes defining it for indexed access easier.
>
> PS: I've thought about this just long enough to write this email, it's
> one of those days... I must have missed something that makes this a
> more complex discussion other than 'this is how we should define the
> value of an indexed access expression'.
>
> --
> Talden
>
>
More information about the coin-dev
mailing list