<br><br><div class="gmail_quote">On Sat, Mar 15, 2008 at 9:51 PM, Neil Toronto <<a href="mailto:ntoronto@cs.byu.edu">ntoronto@cs.byu.edu</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d">Thomas Wouters wrote:<br>
><br>
> On Sat, Mar 15, 2008 at 2:58 PM, Terry Reedy <<a href="mailto:tjreedy@udel.edu">tjreedy@udel.edu</a><br>
</div><div class="Ih2E3d">> <mailto:<a href="mailto:tjreedy@udel.edu">tjreedy@udel.edu</a>>> wrote:<br>
><br>
> | Also, yielding everything from an iterator:<br>
> |<br>
> | >>> def flatten(iterables):<br>
> | ... for it in iterables:<br>
> | ... yield *it<br>
><br>
> Following the general rule above for *exp, that would be the same as<br>
> yield<br>
> tuple(it).<br>
><br>
> No. *exp by itself is not valid syntax:<br>
<br>
</div>Why isn't it? I'd rather have one meaning for the *-prefix operator with<br>
a single special case for assignment targets, than have a bunch of<br>
special cases scattered across the grammar.<br>
</blockquote><div><br>Ehm, the only specialcases in the grammar are for *args and **kwargs in functiondefinitions and functioncalls. There is no specialcase for *exp in either store-context or load-context -- as a matter of fact, the patch to add unpacking in load-context doesn't change the grammar at all.<br>
<br>That *exp by itself is not valid syntax is not new in this patch (PEP-3132 specifies it that way,) and it's easily explained: what the heck would it mean? How does <br><br>t = a, b, c<br><br>differ from<br><br>*t = a, b, c<br>
<br>? In the exact same way, a lone '*exp' in load-context doesn't mean anything. The 'unpacking' unpacks into the surrounding context, and without context it's unclear what the result will be. To clarify,<br>
<br>{*a, b, c, *d} -> a set (dupes removed, order lost)<br>{*a} -> same<br>[*a, b, c, *d] -> a list (dupes intact, order intact)<br>[*a] -> same<br>(*a, b, c, *d) -> a tuple (dupes intact, order intact)<br>
*a, b, c, *d -> same<br>(*a,) -> same<br>*a, -> same (but horrible style)<br>*a -> ?<br><br>The final reduction of (*a, b) is not *a, it's (*a,), just like is the case for (a, b) and (a,). You can say '*exp by itself always unpacks into a list', which Guido argued last night over beer, but that leave that <br>
<br>*a = z<br>a = *z<br><br>do the exact same thing (and the exact same thing as 'a = list(z)' but something quite subtly but importantly different from 'a = z'), and <br><br>a, b, c = *z<br></div></div><br>
differs in no way from<br><br>a, b, c = z<br><br>-- <br>Thomas Wouters <<a href="mailto:thomas@python.org">thomas@python.org</a>><br><br>Hi! I'm a .signature virus! copy me into your .signature file to help me spread!