[Python-ideas] use "as" for block scope support
海韵
lyricconch at gmail.com
Mon Jul 25 18:50:07 CEST 2011
Dupilcate K is used only for describe the scope rule.
Advantage:
1. the same grammer, the same behave
"t" of """(x+y as t, x-y as s) t * s + s + t""" is only valid in the
expression which require
just as
"e" of """except ... as e""" only live in the suite which it belongs
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)
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)
2011/7/25 Bruce Leban <bruce at leapyear.org>:
> On Mon, Jul 25, 2011 at 4:52 AM, 海韵 <lyricconch at gmail.com> wrote:
>>
>> ======example 5==================
>> K = 1
>> A = (K+1 as K, K+2 as Q) K*Q
>> assert A == 6 # (1+1) * (1+2)
>> assert K==1
>> ============example 6===============
>> K = 1
>> A = (K+1 as K) (K+2 as K) K * K
>> assert A == 16 # ((1+1) + 2) * ((1+1) + 2)
>> assert K == 1
>
> With some headscratching, I can figure out these examples. What I can't
> figure out is why you would possibly want to write code like this. It
> certainly doesn't enhance readability, and it wouldn't enhance performance
> or expressiveness of the language either. If you want to propose
> improvements to the language it should do at least one of those things.
> -1 as -1
> --- Bruce
> Follow me: http://www.twitter.com/Vroo http://www.vroospeak.com
>
>
More information about the Python-ideas
mailing list