[Python-ideas] use "as" for block scope support
Terry Reedy
tjreedy at udel.edu
Mon Jul 25 19:41:06 CEST 2011
On 7/25/2011 12:50 PM, 海韵 wrote:
> 2. readability includes laconic
> a = (x+y as t, x-y as s) t * s + s + t
> it doesnt break thinking. from left to right, people finish thinking inplace.
> temp var will not keep in memory, people can forget them since they
> are not valid outside the expression. everything is clean.
> t, s = x+y, x-y
> a = t * s + s + t
> in this case, thinking is break and temp var keep in memory,
> people should take some care about it (for example, in nested loop)
I prefer this. Temporary names are almost never a problem. In a nested
loop, the names are reused and the objects detached for gc.
> 3. this enchant the "lambda" syntax
> list.sort(key = lambda p: (sqrt(p.x**2+p.y**2) as r) r**2+ A*r + B)
I would rather delete lambda rather than enhance it. lambda expressions
that refer to names other than the parameters are a constant source of
confusion.
To me, Python's mixed expression and statement syntax is a feature, not
a wart to be avoided, as this suggestion aims to do.
--
Terry Jan Reedy
More information about the Python-ideas
mailing list