At 11:59 PM 10/18/2005 +1000, Nick Coghlan wrote: >An idea that was kicked around on c.l.p a long while back was "statement >local >variables", where you could define some extra names just for a single simple >statement: > > x = property(get, set, delete, doc) given: > doc = "Property x (must be less than 5)" > def get(self): > try: > return self._x > except AttributeError: > self._x = 0 > return 0 >... > >As I recall, the idea died due to problems with figuring out how to allow the >simple statement to both see the names from the nested block and modify the >surrounding namespace, but prevent the names from the nested block from >affecting the surrounding namespace after the statement was completed.
Haskell's "where" statement does this, but the block *doesn't* modify the surrounding namespace; it's strictly local. With those semantics, the Python translation of the above could just be something like: def _tmp(): doc = "blah" def get(self): # etc. # ... return property(get,set,delete,doc) x = _tmp() Which works great except for the part that co_lnotab won't let you identify that "return" line as being the original expression line, due to the monotonically-increasing bit. ;) Note that a "where" or "given" statement like this could make it a little easier to drop lambda. _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com