On Sat, Mar 15, 2008 at 9:51 PM, Neil Toronto <[EMAIL PROTECTED]> wrote:
> Thomas Wouters wrote: > > > > On Sat, Mar 15, 2008 at 2:58 PM, Terry Reedy <[EMAIL PROTECTED] > > <mailto:[EMAIL PROTECTED]>> wrote: > > > > | Also, yielding everything from an iterator: > > | > > | >>> def flatten(iterables): > > | ... for it in iterables: > > | ... yield *it > > > > Following the general rule above for *exp, that would be the same as > > yield > > tuple(it). > > > > No. *exp by itself is not valid syntax: > > Why isn't it? I'd rather have one meaning for the *-prefix operator with > a single special case for assignment targets, than have a bunch of > special cases scattered across the grammar. > 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. 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 t = a, b, c differ from *t = a, b, c ? 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, {*a, b, c, *d} -> a set (dupes removed, order lost) {*a} -> same [*a, b, c, *d] -> a list (dupes intact, order intact) [*a] -> same (*a, b, c, *d) -> a tuple (dupes intact, order intact) *a, b, c, *d -> same (*a,) -> same *a, -> same (but horrible style) *a -> ? 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 *a = z a = *z 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 a, b, c = *z differs in no way from a, b, c = z -- Thomas Wouters <[EMAIL PROTECTED]> Hi! I'm a .signature virus! copy me into your .signature file to help me spread!
_______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com