[Python-ideas] use "as" for block scope support

Bruce Leban bruce at leapyear.org
Mon Jul 25 19:17:08 CEST 2011


On Mon, Jul 25, 2011 at 9:50 AM, 海韵 <lyricconch at gmail.com> wrote:

> 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)
>

(x + y) * (x - y) + 2 * x

is IMHO more readable - especially note the absence of y in the third term.

>
> 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 don't know what "enchant" means here, but you can do this if you want:

list.sort(key = lambda p: (lambda r: r**2 + A*r + B) (sqrt(p.x**2+p.y**2)))

I'm not recommending that as I think it would be more readable to name that
function so that it would be more clear why you're using that function as
the sort key. But, to me, this example does not justify new syntax.

--- Bruce
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20110725/2e01eb35/attachment.html>


More information about the Python-ideas mailing list