I have the following piece of code for the successor and predecessor of Church numerals: Consider the following code:
(define zero (lambda () '() )) ; Initialize Church numeral zero as nil
(define (succ x) (lambda () x)) ; Wraps x with another function and returns it
(define (pred x) (x)) ; "Unwraps" one shell function of x and returns it
(define one (succ zero)) ; gives me the Church numeral one
(pred one)
Suppose I do the following changes in the pred function:
(define (pred x) x)
What is the difference between returning x and (x)? What exactly does returning (x) mean syntactically and logically?
The function
is the identity function. The function accepts a value and binds it to the argument
x. It then evaluates the bodyxwhich gives the original value back.The function
takes one value as input and binds it the argument
x. It then evaluates the body(x). The expression(x)means call (the hopefully a function)xwith no arguments.So in the context of your encoding
(lamdda () x)wraps a function layer a value and(x)removes the function layer.