[Tutor] python closures

Wayne Werner waynejwerner at gmail.com
Mon Nov 30 13:21:54 CET 2009


On Mon, Nov 30, 2009 at 4:24 AM, spir <denis.spir at free.fr> 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?
>

I'm not sure *why*/how this behaviour really works, other than it treats x
as a global variable... and probably treats n as something similar.

I don't know how bad I find it - you should be declaring the variables
you're planning to use in your function anyway... I'm sure there's *some*
case that it would end out problematic, but I can't think of one ATM.

-Wayne

-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn’t. - Primo Levi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20091130/fe56003f/attachment.htm>


More information about the Tutor mailing list