dynamic functions

Uwe Mayer merkosh at hadiko.de
Tue May 14 12:21:19 EDT 2002


In article <mailman.1021337209.14560.python-list at python.org>, 
brian at sweetapp.com says...

> Two (untested) ways of doing this immediately occur. The most obvious
> is:
> 
> c = lambda x: x < 10
> d = lambda x: c(x) and (x %2 == 0)
> 
> Another way is:
> 
> d = lambda x: x < 10
> def d(x, d=d): return d(x) and (x % 2 == 0)
> The basic problem with your original approach is that you were assuming
> that name resolution is done at compile time, when it is actually done
> at runtime.

Yes, thats the solution. But in return only my question was asked the 
wrong way:
How do you create functions which are resolved by runtime?

To speak cleartext:
I want a class which is initialised with a function in the constructor, 
a = MyClass(lambda x: x < 3)
b = MyClass(lambdy y: y %2 == 0)

which returns a boolean value.
Classes of this type support concatenation in the sense of a logical 
AND, so for: 

a.concate(b)  

a(x) should test for (x < 3) and (x %2 == 0).

How can I do that?
Thanks again - 

Yours
Uwe



More information about the Python-list mailing list