1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
(def vrai  (fn [x] (fn [y] x)))
(def faux  (fn [x] (fn [y] y)))

(def zero  (fn [f] (fn [x] x)))
(def one   (fn [f] (fn [x] (f x))))
(def two   (fn [f] (fn [x] (f (f x)))))
(def three (fn [f] (fn [x] (f (f (f x))))))
(def four  (fn [f] (fn [x] (f (f (f (f x)))))))
(def five  (fn [f] (fn [x] (f (f (f (f (f x))))))))


(defn is-zero [n if-true if-false] ((n if-false) if-true))


(def succ (fn [i]
            (fn [f] (fn [x]
                      (f ((i f) x))))))

(defn ordered-pair [a b] (fn [z] ((z a) b)))
(def zero-pair (fn [z] ((z zero) zero)))
(defn next-pair [pair] (fn [z] ((z (succ (pair vrai))) (pair vrai))))
(defn predecessor [n] (((n next-pair) zero-pair) faux))

(defn multiply [m n]
  (fn [f] (n (m f))))

; You can use the following "realize" function to convert from church numerals to natural numbers for testing.

(defn realize-number [lambda-number] 
  ((lambda-number (partial + 1)) 0))