[Python-ideas] Unpack of sequences

Paul Moore p.f.moore at gmail.com
Thu Aug 30 09:57:51 CEST 2012


On 30 August 2012 02:07, Nick Coghlan <ncoghlan at gmail.com> wrote:
> The obvious form for such a statement is "LHS OP RHS", however
> syntactic ambiguity in the evaluation of both the LHS and RHS
> (relative to normal assigment) would likely prevent that. As a sketch,
> I'll present a notation inspired by Ruby's block parameter syntax and
> emphasising the link to def statements:
>
>     def f(*args):
>         |a=None, b=None| def= *args
>
>     def f(mapping):
>         |a=None, b=None, **other| def= **mapping

I had a similar thought. My initial idea was to introduce a new
keyword "bind" to introduce a binding assignment:

    bind a=None, b=None: *args
    bind a=None, b=None, **other: **mapping

You *might* be able to reuse the def keyword, but I suspect the
ambiguity would be too difficult to resolve.

Rereading the above, the only major issue I see with this is that the
comma/colon distinction is visually a bit too light. Adding parens
might help, but probably gets a bit too punctuation-heavy:

    bind (a=None, b=None): *args
    bind (a=None, b=None, **other): **mapping

Paul.



More information about the Python-ideas mailing list