On Wed, 26 Jul 2000, Guido van Rossum wrote: > > OK, how's that: inner functions have weak reference to variables in the > > same scope > > > > def f(): > > x = 1 > > def g(): > > pass > > Insert "print x" in the body of g, and "return g" in the body of f. What are you trying to do, simulate classes via closures? I don't see any reason for this to work. However, this should work def powers_of(n): return map(lambda x: n**x, range(10)) > Ehm, I'm always confused by the semantics of weak references (you > could say that I haven't a clue about them), so you'd have to do > better than this. > > In any case, in your proposal the weak reference to x would go away > when f returns, so if g is exported from f, it breaks! Exactly. But breaks cleanly, of course (what yo suggested works great) > This behavior is unacceptable, at least to the people who have been > clamoring most for this feature (the Schemers): it is expected that > x is kept alive as long as g lives. Ummmm....to put it harshly f**k Schemers (I'm speaking as a latent schemer myself, so I can be harsh): I don't want lexical scoping to simulate classes, Python's got a wonderful object system. I want lexical scoping to make the common case of map(lambda) or def _(...): .... map(_, ....) less horrible (IOW, without the lambda x,n=n,y=y,something=other: hack) The only question about lexical scoping is "what are we trying to do?". I'm trying to have a working map(). You (seem to be) trying to simulate objects via closures. -- Moshe Zadka <moshez@math.huji.ac.il> There is no IGLU cabal. http://advogato.org/person/moshez
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4