[Python-ideas] Tweaking closures and lexical scoping to include the function being defined

Terry Reedy tjreedy at udel.edu
Mon Sep 26 21:45:48 CEST 2011


On 9/26/2011 7:34 AM, Nick Coghlan wrote:

> Ah, but it *wouldn't* be local, that's the point - it would be stored
> on the function rather than on the frame, and hence be shared across
> invocations.

Today's default arg values are readonly (because stored in an immutable 
structure), quasi-anonymous* closure values used to initialize local 
names. If people understood that better, there would be less puzzlement 
over their behavior. Some of this is tied up with the confusion over 
name and value versus 'variable'.

* They are anonymous in that they are access by index rather than by 
name. On the other hand, the call mechanism deterministically associates 
them with local names.

Nick, I think you are on to something, but I don't know how to get from 
here to there. One of the explicit reasons for introducing closures 
defined by nesting was to reduce default value use. Personally, though, 
I think writing an outer function just for that reason (when only one 
function object is every going to be created, is a cure as bad or worse 
than the disease. When multiple functions are to be created, the new 
closures are an improvement.

-- 
Terry Jan Reedy




More information about the Python-ideas mailing list