
Church numerals
I'm looking for some help in understanding this question in sicp, 2.6:
If zero is
Code:
(define zero(lambda(f)(lambda(x)x)))
And add1 is
Code:
(define(add1 n)
(lambda(f)(lambda(x)(f((n f)x)))))
I'm having a hard time understanding these things.
Zero takes an argument and returns a procedure which simple produces the identity of an argument, is this correct thinking? If so, how is this zero? Wouldn't it be dependent on the input argument?
I'm wondering, is there a way to formulate this with less use of lambda? I'm trying to but I am having a hard time. I'm thinking if I see it without the lbda it may make more sense.
I'm just looking for a bit of help in really understanding it.
Edit: I read up on church numerals and believe I understand it more, basically zero isn't representing the numerical 0, instead an abstraction of the idea of zero. In this case it applies the passed in argument 0 times, correct?
So add 1 will simply increase the amount of times the procedure will be applied to x, in the case of zero, add1 will change zero to one, or
Code:
(define one
(lambda(f)
(lambda(x)
(f x))))
Please tell me this is correct, I think I'm understanding it, it's a bit straining to realize what you are trying to calculate.
Code:
(define three
(lambda(f)
(lambda(x)
(f(f(f x))))))
(three inc 0) would be 3 right?
(define(inc x)
(+ x 1))