This project implements a Lambda Calculus interpreter in Rust. It supports various operations and Church encodings for numbers and boolean values.
This project includes a REPL for interactive use of the Lambda Calculus interpreter. To start the REPL, run the project's main executable.
The REPL supports the following commands:
:help
or:?
- Show the help message:exit
- Exit the REPL:clear
- Clear the screen:last
- Show the last result:log <level>
- Set the log level (error, warn, info, debug, trace)
To evaluate a Lambda Calculus expression, simply type it into the REPL and press Enter.
The interpreter supports the following instructions and operations:
-
Basic Lambda Calculus
- Variable:
x
,y
,z
, etc. - Abstraction:
λx. <expression>
- Application:
(<expression> <expression>)
- Variable:
-
Church Numerals
- Encoding: Automatically handled by the interpreter
- Decoding: Automatically handled by the interpreter
- Predecessor:
pred
- Successor:
succ
- Is Zero:
is_zero
- Multiplication:
multiply
or*
-
Church Booleans
- True:
true
(encoded asλx. λy. x
) - False:
false
(encoded asλx. λy. y
) - And:
and
- Or:
or
- Not:
not
- True:
-
Control Flow
- If-Then-Else:
ifthenelse
- If-Then-Else:
-
Pairs
- Create Pair:
pair
- First Element:
first
- Second Element:
second
- Create Pair:
-
Recursion
- Y Combinator:
Y
- Y Combinator:
Here are some examples of how to use the interpreter:
-
Church Numeral Operations:
(multiply 2 3) (is_zero 0) (pred (succ 5))
-
Boolean Operations:
(and true false) (or true false) (not true)
-
Conditional Statement:
(ifthenelse (is_zero 0) 1 2)
-
Pair Operations:
(pair 1 2) (first (pair 1 2)) (second (pair 1 2))
-
Factorial using Y Combinator:
(Y (λf. λn. (ifthenelse (is_zero n) 1 (multiply n (f (pred n))))))