Le 3 mars 2018 08:45, "Nick Coghlan" <ncogh...@gmail.com> a écrit :

On 3 March 2018 at 11:36, Greg Ewing <greg.ew...@canterbury.ac.nz> wrote:

> 1. Name bindings local to an expression:
>
>    roots = ([(-b-r)/(2*a), (-b+r)/(2*a)] where r = sqrt(b*b-4*a*c))
>
> B. In an expression, surrounded by parentheses for
> disambiguation. Bindings are visible only within the
> parentheses.
>

I'll note that a significant benefit of this approach over the PEP 572
approach is that it would be amenable to a comprehension style
scope-management solution: these expressions could create an implicitly
nested function and immediately call it, just as 3.x comprehensions do.
Adopting such an approach would *dramatically* lower the impact that hiding
the bindings from the surrounding scope would have on the overall name
resolution semantics.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncogh...@gmail.com   |   Brisbane, Australia

_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


As I said, allowing this syntax (whether with a new keyword like 'where' or
reusing something like 'with' to write print(y with y = x+1)) in any
expression (not only after a "for" in a comprehension list) is useful only
if a local scope is created (otherwise, it would be the same as simple
assignement but in reverse ordre).

One could see :

print(y with y = x+1)

As a shortcut for :

print(next(y for y in [ x+1 ]))

The same as this :

[y for x in range(5) with y = x+1]

being a shortcut for :

[y for x in range(5) for y in [ x+1 ]]

As said, allowing both use cases would lead to two different ways to write :

[y for x in range(5) with y = x+1]
vs
[y with y = x+1 for x in range(5)]

But that is not really an issue, it's logically different (is the y a
conclusion of the iteration or a hidden lambda in the expression?).
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to