azreika / lambdul

Lambda calculus interpreter written in Java
8 stars 2 forks source link
interpreter lambda lambda-calculus-interpreter

lambdul

A pure lambda calculus interpreter with built-in macro support.

The interpreter will attempt to reduce any lambda expression to its normal form via α-, β-, and η-reductions.

Setup

Build the interpreter by running ./build from the base directory.

The interpreter can then be used by running ./lambdul from the base directory.

Usage

Basic Expressions

The interpreter accepts lambda expressions in the following format:

A valid identifier is any string satisfying the regex [a-zA-Z]+ - i.e. any string comprised of one or more letters.

An actual λ can be used instead of the backslash \ in an abstraction.

To reduce the need for brackets, the interpreter automatically assumes:

Macros

The interpreter allows the use of macros during a session.

A macro can be assigned with the following syntax:

M := E

where E is any lambda expression, and M is a valid identifier prepended with an underscore (_).

For example, we can assign the following expressions to the _TRUE and _FALSE macros:

_TRUE := \x.(\y.x)
_FALSE := \x.(\y.y)

The macros can then be used as expressions in any input. For instance, the input

((_TRUE \x.x) _FALSE)

is now equivalent to the input

((\x.(\y.x) \x.x) \x.(\y.y))

and will produce the same output:

\x.x

Commands

The interpreter supports the use of certain commands, such as: