lambda in list comprehension acting funny

Dan Stromberg drsalists at gmail.com
Sat Jul 14 20:11:19 EDT 2012


On Sat, Jul 14, 2012 at 4:29 PM, Steven D'Aprano <
steve+comp.lang.python at pearwood.info> wrote:

> I don't remember whether it is Javascript or PHP that uses dynamic
> binding, but whichever it is, it is generally considered to be a bad
> idea, at least as the default or only behaviour.
>
> Bash is another language with dynamic binding. Some very old versions of
> Lisp use dynamic binding, because it was the easiest to implement. Most
> modern languages use lexical (also known as static) binding, because it
> is more sensible.
>
> Here is an illustration of the difference: suppose we have two modules,
> library.py and main.py:
>
> # library.py
> x = 23
> def func(y):
>     return x + y
>
> # main.py
> import library
> x = 1000
> print func(1)
>

I've not heard this discussed  in a while.  ISTR it was "lexical scoping"
vs "dynamic scoping", but I wouldn't be surprised at all if it's known by
both pairs of names.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120714/711816eb/attachment.html>


More information about the Python-list mailing list