elvish
elvish copied to clipboard
Assigning to multiple elements of the same map doesn't work
I just noticed that while you can do multiple variable assignment, multiple map index assignments fail, with only the last map actually getting it's value. Given how multiple variable assignment works, I would expect the same for maps, but for all I know there could be a perfectly logical reason for this behavior. In any case, there is no error message to indicate I'm doing something wrong, so I think that qualifies as a bug?
~> a b = 1 2
~> put $a $b
▶ 1
▶ 2
~> t = [&a= &b=]
~> t[a] t[b] = 3 4
~> put $t
▶ [&a='' &b=4]
~> t = [&a= &b= &c=]
~> t[a] t[b] t[c] = 3 4 5
~> put $t
▶ [&a='' &b='' &c=5]
I also tried doing it another way too, which did return an error message which makes me think that this may just not be implemented yet:
~> t[a b c] = 6 7 8
Exception: multi indexing not implemented
[tty], line 1: t[a b c] = 6 7 8
Interesting, I'm not sure why it doesn't work.
Because of the way element variables work, I'm pretty sure
t[a] t[b] = 3 4
is doing basically
t t = (assoc $t a 3) (assoc $t b 4)
and the RHS is fully evaluated before the first assignment begins so only the last assignment matters.
The same problem exists for lists, very likely for a similar reason:
⬥ var a = [x y z]
⬥ set a[1] a[2] = u v
⬥ put $a
⮕ [x y v]