A simple CLI for working with lambda calculus expressions.
Required Racket to be installed on your system to run. Tested with Racket 6.3.
➜ ~ alonzo -c "(λx.x λz.z)"
OK.
➜ ~ alonzo "(λx.x a)"
a
➜ ~ alonzo -v "((λx.λz.x first) second)"
(λz.first second)
first
# Syntax check an expression
alonzo -c [expression]
# Simplify an expression
alonzo [expression]
# Simplify an expression, showing each β-reduction step
# (TODO)
alonzo -v [expression]
# Identify free variables in an expression
alonzo -f [expression]
# Identify bound variables in an expression
alonzo -b [expression]
Taken from An Introduction to Functional Programming Through Lambda Calculus.
<expression> ::= <name> | <function> | <application>
<name> ::= [a-z]+(-[a-z]+)*
<function> ::= λ <name> . <body>
<body> ::= <expression>
<application> ::= ( <function expression> <argument expression> )
<function expression> ::= <expression>
<argument expression> ::= <expression>
Whitespace is not required except in <application>
, to separate the <function expression>
from the <argument expression>
.
Free variables in the top-level expression will be left as-is. For example, the expression (λx.x b)
simplifies to b
. b
is free in the original expression, and thus is treated as a literal and left as-is.