I have defined Church numeral zero and some other standard functions on church numerals according to Wikipedia definitions as following:
(define n0 (λ (f x) x))
(define newtrue
(λ(m n) m))
(define newfalse
(λ(m n) n))
(define iszero
(λ(m) (m (λ(x) newfalse) newtrue)))
(define ifthenelse
(λ(a b c) (a b c)))
Using these, I write a recursion loop as:
(((λ(r) (λ(n) (ifthenelse (iszero n) n ((r r) n))))
(λ(r) (λ(n) (ifthenelse (iszero n) n ((r r) n))))) n0)
Now for argument n0
as above, this should return n0
, without going into recursion. But it doesn't. Why?
Note 1: This recursion loop works perfectly fine with ordinary numerals and ordinary functions:
(((λ(r) (λ(n) (if (= 0 n) n ((r r) n))))
(λ(r) (λ(n) (if (= 0 n) n ((r r) n))))) 0)
This returns 0
as it should.
Note 2: Functions ifthenelse
, iszero
, newtrue
, newfalse
also work fine on their own.