Guido van Rossum wrote: > > > > > To be honest, I don't think static nested scopes buy us all that > > > > much. You can do the same now, by using keyword arguments which > > > > isn't all that nice, but works great and makes the scope clearly > > > > visible. > > > > > > Yes. It's a hack that gets employed over and over. And it has > > > certain problems. We added 'import as' to get rid of a common > > > practice that was perceived unclean. Maybe we should support nested > > > scopes to get rid of another unclean common practice? > > > > I think the common practice mainly comes from the fact, > > that by making globals locals which can benefit from LOAD_FAST > > you get a noticable performance boost. > > > > So the "right" solution to these weird looking hacks would > > be to come up with a smart way by which the Python compiler > > itself can do the localizing. > > Can you elaborate? I dun't understand what you are proposing here. See my other post... I would like to have the compiler do the localization for me in case it sees a global which has been "defined" static. > > Nested scopes won't help eliminating the current keyword > > practice. > > Why not? I'd say that > > def create_adder(n): > def adder(x, n=n): return x+n > return adder > > is a hack and that nested scopes can fix this by allowing you to write > > def create_adder(n): > def adder(x): return x+n > return adder > > like one would expect. (Don't tell me that it isn't a FAQ why this > doesn't work!) I know... still, I consider function definitions within a function bad style. Maybe just me, though ;-) > > > I'm not saying that we definitely should add this to 2.1 (there's > > > enough on our plate already) but we should at least consider it, and > > > now that we have cycle GC, the major argument against it (that it > > > causes cycles) is gone... > > > > Hmm, so far the only argument for changing Python lookups > > was to allow writing lambdas without keyword hacks. Does this > > really warrant breaking code ? > > > > What other advantages would statically nested scopes have ? > > Doing what's proper. Nested scopes are not a bad idea. They weren't > implemented because they were hard to get right (perhaps impossible > without creating cycles), and I was okay with that because I didn't > like them; but I've been convinced that examples like the second > create_adder() above should reall work. Just like float+int works > (in Python 0.1, this was a type-error -- you had to case the int arg > to a float to get a float result). Ok, but how does nested scoping mix with class definitions and global lookups then ? -- Marc-Andre Lemburg ______________________________________________________________________ Business: http://www.lemburg.com/ Python Pages: http://www.lemburg.com/python/
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