the demise of 'from foo import * and its implications?

Tim Peters tim.one at home.com
Sat Mar 3 15:21:19 EST 2001


[Robin Becker]
>>> If we really want to improve visibility we could try to make
>>>
>>> >>> def bingo(a):
>>> ...     if a<=1: return 0
>>> ...     return bingo(a-1)*a
>>> ...
>>>
>>> work naively, but I'm fairly sure this will be rejected as unpythonic or
>>> somesuch.

[Tim Hochberg]
>>?????
>>
>> In what sense doesn't this work now?
>> ...
>>
>>What doesn't work is the following:
>>
>>def spam(n):
>>   def fact(a):
>>      if a <= 1: return 1
>>      else: return fact(a-1)*a
>>   return fact(n) + 42

[Robin Becker]
> you're right of course, this is what I meant. I haven't played with the
> new statically scoped stuff, but I probably wrongly assumed that bingo
> would remain invisible inside bingo.

Ah!  Yes, that assumption is wrong.  Making nested recursive functions "work"
as expected was one of the (few) strong *practical* arguments in favor of
adding nested_scopes.

> ...
> I hadn't really appreciated before now that python wishes to enforce a
> fixed scope for references (for optimisation purposes)

See other reply:  "optimization" is incidental here.  Python wants static
scoping *primarily* for sanity.  Dynamic scoping is more error-prone because
more surprise-prone.





More information about the Python-list mailing list