Y combinator
Miki Tebeka
mtebeka at iil.intel.com
Sun Nov 5 03:04:49 EST 2000
Hello All,
I'm trying to write a the Y combinator in Python.
Since Python has no closures I'm using classes.
I've tried:
class Y:
def __init__(self, func):
self.__func = func
def __call__(self, f):
return (self.__func (f (f))) (self.__func (f (f)))
def y_fact(f, n):
if (n == 0):
return 1
else:
return n * f(n -1)
fact = Y(y_fact)
fact(3)
and I get
Traceback (innermost last):
File "c:\miki\python\y.py", line 15, in ?
fact(3)
File "c:\miki\python\y.py", line 6, in __call__
return (self.__func (f (f))) (self.__func (f (f)))
TypeError: call of non-function (type int)
Any help?
Bye.
------------------------------------------------------------------------------
Smile, damn it, smile.
lambda msg: {
'name' : 'Miki Tebeka',
'email' : 'tebeka at lycosmail.com',
'homepage' : 'www.tebeka.freeservers.com',
'quote' : "I don't suffer from insanity, I enjoy every minute of it."
}[msg]
More information about the Python-list
mailing list