How can I make Church numerals more human readable in lisp?

Posted by Jason Baker on Stack Overflow See other posts from Stack Overflow or by Jason Baker
Published on 2010-04-20T13:46:16Z Indexed on 2010/04/20 13:53 UTC
Read the original article Hit count: 166

I can define church numerals fairly easy using scheme:

> (define f (lambda (x) x))
> (f f) ;0
#<procedure:f>
> (f (f f)) ;1
#<procedure:f>

However, this doesn't make it very easy to recognize that (f f) is 0 and (f (f f)) is 1. Is there a way that I can make these numerals more readable? What would be ideal is this:

> (f f)
0
> (f (f f))
1

The example is in scheme, but I'll take an answer in any lisp.

© Stack Overflow or respective owner

Related posts about church-encoding

Related posts about lambda