[Python-ideas] PEP 572: Statement-Local Name Bindings, take three!

Cammil Taank ctaank at gmail.com
Tue Mar 27 18:45:53 EDT 2018


>
> ... From here,
> the most important concern and question is: Is there any other syntax
> or related proposal that ought to be mentioned here?


I am not sure if this is valid, but perhaps this is an alternative syntax
which might be simpler:

``name! expr``

So for example, instead of:

    stuff = [[(f(x) as y), x/y] for x in range(5)]

    stuff = [[y! f(x), x/y] for x in range(5)]

As far as I can tell there would be no conflicts with the current uses of "!".

One potential source of ambiguity would be in:

x = y! a + b     # should y be a or (a + b)?

I think this is solved by requiring the target expression to be
non-greedy. If you want a larger named expression, you can always use
parenthesis. i.e. ``x = y! (z + z)``

I feel brevity and minimised punctuation are important for the
adoption of statement-locals, and personally I feel it reads well. I
also happen to prefer the name preceding the expression, though I
suspect this is quite subjective.

Also, apologies if I have grossly misunderstood something.

Cammil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180327/7919bd35/attachment.html>


More information about the Python-ideas mailing list