The Y combinator is a higher-order function that allows a function that does not know its own name to call itself. It is the fundamental basis of recursion.
The Y combinator is a higher-order function that allows a function that does not know its own name to call itself. It is the fundamental basis of recursion.
In Scheme syntax:
(define Y
(lambda (f)
(f (lambda (x) ((Y f) x)))))
To implement Fibonacci recursively with Y:
(define fibonacci
(Y
(lambda (f)
(lambda (n)
(if (= n 0)
1
(* n (f (- n 1))))))) ))
A nice article on the topic is at: http://mvanier.livejournal.com/2897.html