[Python-ideas] Javascript Destructuring Assignment

Brett Cannon brett at python.org
Tue Mar 6 20:26:20 CET 2007


On 3/6/07, Jim Jewett <jimjjewett at gmail.com> wrote:
> On 3/5/07, Brett Cannon <brett at python.org> wrote:
> > On 3/5/07, Talin <talin at acm.org> wrote:
> > >     http://developer.mozilla.org/en/docs/New_in_JavaScript_1.7
> ...
>
> > >    [a,,b] = [1,2,3]
> > >
> > > In other words, a is assigned the value 1, the value 2 is thrown away,
> > > and b is assigned the value 3. In today's Python, this requires a dummy
> > > variable.
>
> > It skips in the middle?!?  Yuck.
>
> Are you assuming variable-length skips, so that
>
>     [a,,b] = [1,2,3,4,5]   would mean a=1;b=5 ?
>

Yep, that's how I read it.

> I had read it is just not requiring a name for the unused dummy
> variable.  It doesn't really seem worse than
>
>     [a, _junk, b] = [1,2,3]
>
> or less explicit than
>
>     [a,_,b] = [1,2,3]

Right, but why the ends?  And what if that example had three variables
to unpack to, e.g., a, b, and c?  With a = 1 and c = 5, what does b
get?  2, 4, 3?  It can be intrepreted in so many ways its ambiguous
without referencing the documentation.

-Brett



More information about the Python-ideas mailing list