Anonymous recursion: Difference between revisions

m
Line 1,316:
 
Same thing as the above, but modified so that the function is uncurried:
<lang python>>>>from functools import partial
<lang python>>>> Y = lambda f: (lambda x: x(x))(lambda y: partial(f, lambda *args: f(y(y), (*args)))
>>> fib = lambda f, n: None if n < 0 else (0 if n == 0 else (1 if n == 1 else f(n-1) + f(n-2)))
>>> [ Y(fib)(i) for i in range(-2, 10) ]
Anonymous user