[Python-Dev] 2.5 and beyond

Josiah Carlson jcarlson at uci.edu
Tue Jul 4 02:20:28 CEST 2006


"Bill Chiles" <billchi at microsoft.com> wrote:
> 
> For Common Lispers and probably Schemers, Python has some surprising
> semantics around scope and lifetime extent of variables.  Three that
> leap out at me are:

One thing to remember is that Python is not Scheme/Lisp.  It borrows
some ideas from Scheme/Lisp, but that borrowing does not necessitate a
it also use a completely equivalent scoping mechanism.  From what I have
been hearing about Python 2.6, and 3.0, the three "surprises" you
describe are not going to be "fixed" (with respect to expected
Scheme/Lisp semantics).

Feel free to argue as to why they should be "fixed" in Py3k (unless
Guido says, "you're dreaming"), but please do so in the py3k list.

 - Josiah


>  * function parameters with default values are NOT new bindings for each
> invocation, so a
>    default value of [] changes if you destructively modify this list
> object in the function
>  * loop variables are NOT distinct lexical variables.  The binding gloms
> on to a variable in the
>    function's scope, both changing that lexical binding and not creating
> a new one for the
>    loop (that goes away when the loop's scope ends)
>  * loop variables are NOT distinct bindings per iteration, leading to
> the surprising results
>    below



More information about the Python-Dev mailing list