Created
July 15, 2013 15:12
-
-
Save dsabanin/6000742 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def first (fn [first] | |
(fn [second] first))) | |
(def second (fn [first] | |
(fn [second] second))) | |
(def make-pair (fn [first] (fn [second] (fn [func] ((func first) second))))) | |
(def TRUE first) | |
(def FALSE second) | |
(def COND (fn [exp1] | |
(fn [exp2] | |
(fn [c] | |
((c exp1) exp2))))) | |
(def NOT (fn [c] | |
(((COND FALSE) TRUE) c))) | |
(def AND (fn [exp1] | |
(fn [exp2] | |
(((COND exp2) FALSE) exp1)))) | |
(def OR (fn [exp1] | |
(fn [exp2] | |
(((COND TRUE) exp2) exp1)))) | |
(def zero identity) | |
(def succ (fn [n] | |
(fn [s] ((s FALSE) n)))) | |
(def pred (fn [n] | |
(n second))) | |
(def iszero (fn [n] | |
(n first))) | |
(def pred (fn [n] | |
(((iszero n) n) (n second)))) | |
(def one (succ zero)) | |
(def two (succ one)) | |
(def three (succ two)) | |
(def two (pred three)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment