Y-combinator is a way of defining a function that can call itself without the define function.
Y-combinator is a way of defining a function that can call itself without the define function.
Date Created:Tuesday September 30th, 2008 10:43 AM
Date Modified:Tuesday January 19th, 2010 10:35 PM
First, create the function for passing in the parameters:
(lambda (x)Now, create the function that will pass the function that it receives as input into that function that it receives. Let function a be the function we are creating. Function b is an argument to a. Function a will call b with b as an argument to b, along with its argument. This is what we call the "Y-combinator":
(lambda (f n) (f f n))Now create the function that actually does what we want. the procedure we may want to call it.
(lambda (factorial n)
(if (= n 0)
1
(* n (factorial factorial (- n 1)))))
Now pass in the initial argument
x))
(lambda (x) (lambda (f n) (f f n)) (lambda (factorial n) (if (= n 0) 1 (* n factorial factorial (- n 1))))) x))
Downloads:
Download: y-comb.scm 157 B
Please login or Click Here to register for downloads
Y-combinator by Dan Lynch
is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
Based on a work at www.3daet.com
Permissions beyond the scope of this license may be available at http://www.3daet.com
