Thanks for he repro and bug report, Jacques, the bug you see is caused by
missing implementation of closures in IronPython. The closure implementation is
on our to-do list.
Thanks!
Martin From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of J. de Hooge Sent: Friday, September 02, 2005 7:18 AM To: users-ironpython.com@lists.ironpython.com Subject: [IronPython] self not known in lambda function # Hi, # # Might this be a small bug in IronPython? 'self' is not known inside the definition of a lambda function # I tried to insulate the problem in a small (admittedly pointless) program, not to bother you with bulky app. code # I am using IronPython 0.9.1 # < # Jacques de Hooge [EMAIL PROTECTED] # # This example will print the following: # ====================================== # # workaround # Traceback (most recent call last): # at __main__.Initialize() in C:\activ_dell\prog\fun\src\funDebug.py:line 29 # at __main__.lamda$1$f5() # NameError: name 'self' not defined # # ======================================
class WorkAround: def __init__ (self): global this this = self self.setPrintWithoutParams (lambda: this.printWithParams ('workaround'))
def printWithParams (self, text): print text
def setPrintWithoutParams (self, printWithoutParams): self.printWithoutParams = printWithoutParams
workAround = WorkAround () workAround.printWithoutParams ()
class Problem: def __init__ (self): self.setPrintWithoutParams (lambda: self.printWithParams ('problem'))
def printWithParams (self, text): print text
def setPrintWithoutParams (self, printWithoutParams):> self.printWithoutParams = printWithoutParams
problem = Problem () problem.printWithoutParams ()
|
_______________________________________________ users-ironpython.com mailing list users-ironpython.com@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com