[Python-ideas] A "local" pseudo-function
Steven D'Aprano
steve at pearwood.info
Mon Apr 30 11:45:51 EDT 2018
On Sat, Apr 28, 2018 at 11:20:52PM -0500, Tim Peters wrote:
> [Tim]
> >> Enormously harder to implement than binding expressions, and the
> >> latter (to my eyes) capture many high-value use cases "good enough".
>
> [Steven D'Aprano <steve at pearwood.info>]
> > And yet you're suggesting an alternative which is harder and more
> > confusing.
>
> I am? I said at the start that it was a "brain dump". It was meant
> to be a point of discussion for anyone interested. I also said I was
> more interested in real use cases from real code than in debating, and
> I wasn't lying about that ;-)
Ah, my mistake... I thought you were advocating sublocal scopes as well
as just brain dumping the idea.
[...]
> > Even when I started, as a novice programmer who wouldn't have recognised
> > the term "lexical scoping" if it fell on my head from a great height, I
> > thought it was strange that inner functions couldn't see their
> > surrounding function's variables. Nested scopes just seemed intuitively
> > obvious: if a function sees the variables in the module surrounding it,
> > then it should also see the variables in any function surrounding it.
> >
> > This behaviour in Python 1.5 made functions MUCH less useful:
[...]
> > I think it is fair to say that inner functions in Python 1.5 were
> > crippled to the point of uselessness.
>
> I don't think that's fair to say. A great many functions are in fact
> ... functions ;-) That is, they compute a result from the arguments
> passed to them.
Sure, but not having access to the surrounding function scope means that
inner functions couldn't call other inner functions. Given:
def outer():
def f(): ...
def g(): ...
f cannot call g, or vice versa.
I think it was a noble experiment in how minimal you could make scoping
rules and still be usable, but I don't think that particular aspect was
a success.
--
Steve
More information about the Python-ideas
mailing list