Skip to content

Instantly share code, notes, and snippets.

@y-yu
Created November 10, 2015 16:11
Show Gist options
  • Save y-yu/a1370698ed533bbbdd8a to your computer and use it in GitHub Desktop.
Save y-yu/a1370698ed533bbbdd8a to your computer and use it in GitHub Desktop.
nil = \x x
cons = \x \y \f f x y
car = \x \y x
cdr = \x \y y
true = \x \y x
false = \x \y y
if = \b \t \e b t e
zero = \f \x x
succ = \n \f \x f (n f x)
pred = \n \f \x n (\g \h h (g f)) (\u x) (\u u)
is_zero = \n n (\x false) true
plus = \m \n m succ n
c_to_n = \n n (\x +<1, x>) 0
fib = \f \n \a if (is_zero n) (a car) (f f (pred n) (cons (plus (a car) ((a cdr) car)) (cons (a car) nil)))
print (c_to_n (fib fib (succ (succ (succ (succ zero)))) (cons (succ zero) (cons zero nil))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment