[Python-ideas] Javascript Destructuring Assignment
Ron Adam
rrr at ronadam.com
Wed Mar 7 07:13:24 CET 2007
Brett Cannon wrote:
> On 3/5/07, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
>> Brett Cannon wrote:
>>
>>> I personally am -1 on the idea. Explicit is better than implicit.
>> One thing I *would* like to see, that Javascript doesn't
>> seem to have either yet, is a *-arg on the end of the
>> unpacking list:
>>
>> a, b, *c = [1, 2, 3, 4, 5]
>>
>> giving a == 1, b == 2, c == [3, 4, 5].
>>
>
> Now I know that was discussed on python-dev once, but I don't remember
> why didn't end up happening.
(If I recall correctly) There was some support for using the '*' outside of
function signatures. I think it died out because of too many alternative
suggestions. Or there was some sort of ambiguous situations I'm not
remembering, possibly confusion with the multiply operator.
I have mixed feeling on it myself. The reason being, (to me), using the
'*' for both packing and unpacking is not the most readable solution.
Also the '*' syntax can't be used to unpack nested items.
>>> data = [1, [2, [3, 4]]]
>>> a, (b, (c, d)) = data
>>> print a, b, c, d
1 2 3 4
Ron
More information about the Python-ideas
mailing list