# Church numerals

Okay, so, Jens asked me to make a Church numeral project.

Lambda calculus, the ultimate source of the λ in the Snap! logo, is a branch of mathematics that describes an abstract computer that only has the features and . It turns out that that's all you need to build up to all the standard functions you expect in a programming language, and in particular, the arithmetic operators.

Church numerals are a representation of the nonnegative integers in lambda calculus. This handout and this starter project are all you need if you want to try it. I figure you lot can find any bugs in it before Jens uses it in public. :~)

(Why would you want to program with your hands tied behind your back like this? You wouldn't, not for practical programming, but it's a great environment for proving theorems about what computers can do, e.g., that some functions are uncomputable.)

P.S. Make the stage small.

Here you mentioned that some slight change was needed in how upvars are "scoped" (can I say so, is it grammaticaly correct?) in order for this project to work.

I didn't quite understand last time when you mentioned it, what change exactly was done by Jens now that this is now possible?

I know you gave the two examples above, but I still didn't understand. Can you explain it again, please.

I don't know if that was intentional, but all the tries below try three report error.

You're supposed to make the "plus" function, and then do the tries

Ah. I see.
EDIT:
Even when I set plus to ??? it reports error.

The handout says:

The function you’re going to write is much simpler than the official Y combinator, because reasons ...

Where reasons looks like a link but clicking on it does nothing in Acrobat.

He didn't. In the handout there's a big complicated explanation of why if-then-else has to be implemented as a regular Snap! procedure rather than a naked gray ring. In the version I want to build, the project has its own evaluator using normal order, so if-then-else doesn't have to be a special case.

If you look at all the examples in the project, a bunch of formal parameters come up repeatedly: NUMBER, X, F, etc. I need to be able to have two lambda expressions in the same script, each of which has its own version of its formal parameters.

Those ??? blocks are places where you're supposed to write the code! I guess that wasn't clear enough. I'll edit the handout...

Grr, this is a problem for Mac users -- you can't make active links in a PDF on the Mac because of a war between Adobe and Apple.

It should point here:

quick question what kind of functions are we doing with le numerals(i haven't been on in about 4 months so i'm more than useless actually,but i'd like to at least try)

Umm did you look at the handout? It walks you through inventing arithmetic.

no not yet i just wanted confirm i wasn't going crazy cause i didn't see anything relating to functions until the last paragraph

It's all functions! But they're anonymous functions (lambda expressions (gray rings)) rather than using the make-a-block mechanism.

I realize that now

Would it be reasonable for Church Integers to convert between the two representations of an integer i as (n, m) where i = n - m (which plays nicer with addition and subtraction) and (sign, n) (which plays nicer with multiplication and division), just as Snap! converts between Arrays and Linked Lists?

Umm, sure, you could invent whatever representation you want. Not sure you can call them "Church numerals" if you don't do it the way Alonzo Church did it... :~D