Matthias Wächter
2/22/2008 10:46:00 AM
Mark,
thanks for your perfect explanation of the problem, you clearly make my point. :)
Mark Bush wrote:
> The problem is: what is the value of a after:
>
> a, b, c = d
>
> ?
> The answer is: it depends. If d is an array, then a becomes d[0],
> otherwise a becomes d. Since you can write:
>
> a, b, c = "hi", "hello", "wassa"
>
> setting each value, and:
>
> a, b, c = "hi"
To make inconsistencies even more stupid, we could specify that
a,b,c,d,e = "aeiou"
results in a=="a", b=="e", c=="i", d=="o", e=="u".
or
a,b,c,d = 5
could be interpreted as a bit-wise split assignment such that a==0, b==1, c==0, d==1. I see no point in allowing an array to be treated specially, even more so as there is the one-character splat operator available.
> Further, consider this example:
>
> a = [[1, 2, 3]]
> b, c, d = *a
>
> What is the value of b? Since the multiple assignment is "equivalent"
> to:
>
> b, c, d = [1, 2, 3]
>
> it would seem that the way arrays automagically expand would result in b
> becoming 1, but actually b becomes the array [1, 2, 3] meaning that
> automagic expansion is not happening. So even the inconsistency is
> inconsistent!
Yeah, thanks for this perfect example of the matter!
> The semantics of assignment should not change just because the class of
> something on the rhs changes.
My words.
Was this discussed already so that we know what Matz thinks about it, or should we bring this topic up on ruby-core?
- Matthias