<br><br><div class="gmail_quote">On Sat, Mar 15, 2008 at 9:51 PM, Neil Toronto &lt;<a href="mailto:ntoronto@cs.byu.edu">ntoronto@cs.byu.edu</a>&gt; 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>
&gt;<br>
&gt; On Sat, Mar 15, 2008 at 2:58 PM, Terry Reedy &lt;<a href="mailto:tjreedy@udel.edu">tjreedy@udel.edu</a><br>
</div><div class="Ih2E3d">&gt; &lt;mailto:<a href="mailto:tjreedy@udel.edu">tjreedy@udel.edu</a>&gt;&gt; wrote:<br>
&gt;<br>
&gt; &nbsp; &nbsp; | Also, yielding everything from an iterator:<br>
&gt; &nbsp; &nbsp; |<br>
&gt; &nbsp; &nbsp; | &gt;&gt;&gt; def flatten(iterables):<br>
&gt; &nbsp; &nbsp; | ... &nbsp; &nbsp; for it in iterables:<br>
&gt; &nbsp; &nbsp; | ... &nbsp; &nbsp; &nbsp; &nbsp; yield *it<br>
&gt;<br>
&gt; &nbsp; &nbsp; Following the general rule above for *exp, that would be the same as<br>
&gt; &nbsp; &nbsp; yield<br>
&gt; &nbsp; &nbsp; tuple(it).<br>
&gt;<br>
&gt; No. *exp by itself is not valid syntax:<br>
<br>
</div>Why isn&#39;t it? I&#39;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&#39;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&#39;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 &#39;*exp&#39; in load-context doesn&#39;t mean anything. The &#39;unpacking&#39; unpacks into the surrounding context, and without context it&#39;s unclear what the result will be. To clarify,<br>
<br>{*a, b, c, *d} -&gt; a set (dupes removed, order lost)<br>{*a} -&gt; same<br>[*a, b, c, *d] -&gt; a list (dupes intact, order intact)<br>[*a] -&gt; same<br>(*a, b, c, *d) -&gt; a tuple (dupes intact, order intact)<br>
*a, b, c, *d -&gt; same<br>(*a,) -&gt; same<br>*a, -&gt; same (but horrible style)<br>*a -&gt; ?<br><br>The final reduction of (*a, b) is not *a, it&#39;s (*a,), just like is the case for (a, b) and (a,). You can say &#39;*exp by itself always unpacks into a list&#39;, 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 &#39;a = list(z)&#39; but something quite subtly but importantly different from &#39;a = z&#39;), 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 &lt;<a href="mailto:thomas@python.org">thomas@python.org</a>&gt;<br><br>Hi! I&#39;m a .signature virus! copy me into your .signature file to help me spread!