[Python-ideas] Fwd: Fwd: unpacking generalisations for list comprehension
אלעזר
elazarg at gmail.com
Thu Oct 13 17:06:42 EDT 2016
On Thu, Oct 13, 2016 at 11:59 PM Paul Moore <p.f.moore at gmail.com> wrote:
> On 13 October 2016 at 21:47, אלעזר <elazarg at gmail.com> wrote:
> > if you allow result.append(1, 2, 3) to mean result.extend([1,2,3]) #
> which
> > was discussed before
>
> I don't (for the reasons raised before). But thank you for your
> explanation, it clarifies what you were proposing. And it does so
> within the *current* uses of the * symbol, which is good. But:
>
> 1. I'm not keen on extending append's meaning to overlap with extend's
> like this.
> 2. Your proposal does not generalise to generator expressions, set
> displays (without similarly modifying the set.add() method) or
> dictionary displays.
> 3. *fn(x) isn't an expression, and yet it *looks* like it should be,
> and in the current syntax, an expression is required in that position.
> To me, that suggests it would be hard to teach. [1]
>
> You can of course generalise Sjoerd's "from" proposal and then just
> replace "from" with "*" throughout. That avoids your requirement to
> change append, but at the cost of the translation no longer being a
> parallel to an existing use of "*".
>
>
I think it is an unfortunate accident of syntax, the use of "yield from
foo()" instead of "yield *foo()". These "mean" the same: a syntactic
context that directly handles iterable as repetition, (with some guarantees
regarding exceptions etc.). Alternatively, we could be writing [1, 2, from
[3, 4], 5, 6]. Whether it is "from x" or "*x" is just an accident. In my
mind.
As you said, the proposal should be written in a much more formal way, so
that it could be evaluated without confusion. I completely agree.
Elazar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20161013/2913874c/attachment.html>
More information about the Python-ideas
mailing list