I'm learning lambda calculus these days and found it very beautiful and interesting, but I haven't found out how to implement the EQ primitive of LISP, which judges if two symbols are the same.
I have found many materials for implementing integer arithmetic (using Church Numbers) and boolean logic, but failed to find a solution for EQ. I hope EQ works like this(the same of LISP):
(EQ x x) --> True
(EQ x y) --> False
(EQ (x y) (x y)) --> False // return true only for simple symbols, not structures
Any help.
Update:
I do not mind to wrap symbols into some contexts, for example:
(EQ (lambda u . u symbol x) (lambda u . u symbol x)) --> True
(EQ (lambda u . u symbol x) (lambda u . u symbol y)) --> False
I've found a possible solution:
If we restrict symbols in a finite set, e.g., Symbols = {A, B, C}, then we can define an EQ like this:
A = λ A B C. A
B = λ A B C. B
C = λ A B C. C
EQ = λ x y. ChurchEQ (x 1 2 3) (y 1 2 3) // Here 1, 2, 3 should be replaced by Church Numbers
I have tested these code in an interpreter, and it works.
But one problem remains: The EQ itself can't be placed into Symbols.
((lambda symbol. symbol) 1)evaluate to? - Will NessEQ (λu.ux) (λu.uy)inside(λy.(λx.EQ (λu.ux) (λu.uy)) y)evaluate to? - Will Ness