[Tutor] python closures

Eike Welk eike.welk at gmx.net
Wed Jan 27 14:04:06 CET 2010

Hello Denis!

On Monday November 30 2009 11:24:45 spir wrote:
> which seems to indicate python really embeds "symbolic references" (*) to
>  outer *variables*, when creating a closure for g0. Not "pointer
>  references" (**), otherwise the replacement of x would not be seen by the
>  closure --like in the case of default-parameter. Actually, I find this
>  _Bad_. Obviously, the func's behaviour and result depend on arbitrary
>  external values (referentially opaque). What do you think?
> Denis
> (*) by name, indirect access, second table lookup
> (**) by address, direct access, no second lookup

I just skimmed over introductions to Oz and Ocaml, and both programming 
languages seem to behave the way that you prefer. The closure consists of 
pointers to the objects and can't be modified. (Both languages however have 
special syntax for global variables that can be modified.)

So, Python's behavior is just a design decision; and more people dislike it,  
like you. 

Learning exotic programming languages seems to widen my horizon.


More information about the Tutor mailing list