Closures in leu of pointers?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sun Jun 30 07:22:24 EDT 2013


On Sun, 30 Jun 2013 01:56:25 -0700, rusi wrote:

[...]
> All of which adds up to making scoping/variables an arcane craft.
> 
> Now having such passes is one thing. Defining the language in terms of
> them quite another...

I don't believe that Python's behaviour is defined in terms of the number 
of passes. It is defined in terms of a condition "if you assign to a 
name, it is local unless declared global". Parsing the function twice 
just happens to be the simplest way for the compiler to implement that 
rule, but it's not strictly necessary. A skilled human reader, for 
example, may read the function once, and re-interprete what's already 
seen on the basis of what they've just seen. For a human reader, such 
backtracking is probably easier than a two-pass process explicitly 
memorizing which variables are local and which are global. 



-- 
Steven



More information about the Python-list mailing list