[Python-ideas] Tweaking closures and lexical scoping to include the function being defined
Nick Coghlan
ncoghlan at gmail.com
Thu Sep 29 21:56:20 CEST 2011
On Thu, Sep 29, 2011 at 3:47 PM, Terry Reedy <tjreedy at udel.edu> wrote:
> One is to reproduce the behavior of defaulted parameters without having the
> name appear in the signature to produce *read-only* private locals, which
> amount to private define-time constants. This includes the int=int type
> speed hack. I think '*, _int=int', with adjustment of introspection, is
> sufficient. This make '_int' pragmatically constant, while still externally
> over-rideable for exceptional purposes such as testing or tracing.
Well, the references would be constant. The state itself could still
be mutable, depending on the kinds of objects referred to.
I agree this use case could be addressed by blessing the status quo
and a couple of conventions.
> The other is to introduce something new: private *read-write* closure
> (persistent) name-value pairs. I agree that such a new thing should not be
> in the param list between '(' and ')'.
It's not actually new as far as overall language capabilities go -
since PEP 3104, you can get the functionality through appropriate use
of an ordinary closure. It's really just about providing a slightly
shorter syntax for a particular way of using closures.
Well noted that not all proposals are addressing the same
functionality, though.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas
mailing list