Closures in leu of pointers?

rusi rustompmody at gmail.com
Sun Jun 30 03:36:56 EDT 2013


On Sunday, June 30, 2013 10:38:01 AM UTC+5:30, Chris Angelico wrote:
> On Sun, Jun 30, 2013 at 2:32 PM, Terry Reedy  wrote:
> > One of the reasons I switched to Python was to not have to do that, or
> > hardly ever. For valid code, an new declaration is hardly needed. Parameters
> > are locals. If the first use of another name binds it (and that includes
> > import, class, and def), it is local. If the first use of does not bind it,
> > it had better not be local (because if it is, there well be an exception).
> > If there are branches, each should be consistent with the others. One should
> > only need two readings to understand and fix unbound local errors.
> 
> 
> This is strictly a matter of opinion, and one on which mine differs
> from yours. I think explicit declarations are better than implicit
> "you've assigned to this name" local creations; the declarations help
> to catch typos. Also, I like the consistency of C-style declarations -
> where-ever you declare something, it's valid from there "in", and not
> "out". Without declarations, there's a magical scope boundary at a
> function definition that's different from the non-boundary at a loop,
> for instance.
> 
> 
> But that's just my opinion. and as Teresa says, I'm only one, and
> possibly I'm wrong.

Getting scoping right has been -- history-wise -- exceptionally difficult.

Lisp started with dynamic scoping -- the word and the consequences of that hardly being conceivable in 1960.  It took 25 years to correct half that error in scheme and common-lisp viz. dynamic to static scoping.  The other half still persists in common lisp though not scheme
http://en.wikipedia.org/wiki/Lisp-1_vs._Lisp-2#The_function_namespace.

Its taken another 25 years to get the mistake out of the most ubiquitous lisp -- Emacs-lisp
https://en.wikipedia.org/wiki/Emacs_Lisp#From_dynamic_to_lexical_scoping

I believe perl started with 'local' and later added 'my', repeating the same mistake.

Even python needed to modify the LEGB rule (was it 2.2??) for similar reasons,
got comprehension scoping wrong by having variables leak out -- corrected from 2 -> 3, and still gets it wrong from one element to the next.

And finally, the founders of lambda-calculus -- Church, Curry, Rosser -- screwed up (I believe) in the initial definitions of free and bound variables.



More information about the Python-list mailing list