[Python-ideas] PEP 505 (None coalescing operators) thoughts

Random832 random832 at fastmail.com
Thu Oct 1 01:07:27 CEST 2015


On Wed, Sep 30, 2015, at 18:42, Nikolaus Rath wrote:
> On Sep 30 2015, Andrew Barnert via Python-ideas
> <python-ideas-+ZN9ApsXKcEdnm+yROfE0A at public.gmane.org> wrote:
> > Also, explicit "it" would be usable in other situations:
> >
> >     z = dangerous_thing(arg) if it.value() > 3 else DummyValue(3)
> 
> Really? I'm not sure if "it" is "dangerous_thing" or
> "dangerous_thing(arg)".

I thought it was arg, though it's a bit silly for it to be.

Why not go full Scheme and add a way to do lexical expressions that
capture values for multiple use:

z = (let it=arg: dangerous_thing(it) if it.value() > 3 else
DummyValue(3))

Would be equivalent to

z = (lambda it: dangerous_thing(it) if it.value() > 3 else
DummyValue(3))(arg)

Only without necessarily actually instantiating a lambda (i.e. it could
push the result of arg [which may be any expression] onto the stack or
in an anonymous or obscurely-named local variable slot to refer whenever
it is referenced in the inner expression.


More information about the Python-ideas mailing list