lambda closure question

jfj jfj at freemail.gr
Mon Feb 21 20:50:08 EST 2005


Carl Banks wrote:

> transformations gets rebound, so you'd need a reference to it.

That certainly is an application.  I guess it depends on one's
programming background.

I'd only use nested (function, class) definition to accomplish
such a feature:

########################
def genclass(x,y):
     class myclass:
         M = x
         def f(self, z):
             return self.M + y + z
     return myclass

A=genclass(1,2)
a=A()
#########################

where i would prefer python to expand this as a template to:

     class myclass:
         M = 1
         def f(self, z):
             return self.M + 2 + z
     A = myclass
     a = A()

IOW, I'd like nested (function, class) definitions to
be used *only* for dynamic code generation with runtime
constants, and OOP *forced* for other applications like
the fractal example:)

jf
---------------
# if you're dissatisfied with the situation on the planet
# slow down the circulation of money




More information about the Python-list mailing list