A lambda calculus engine
This repository has been archived on 2024-11-05. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
Go to file
Mark 787dbd9091
Added vhs tape
2022-11-12 18:16:35 -08:00
.vscode Improved history & highlighting 2022-11-11 17:04:05 -08:00
lamb_engine More reliable ctrl-c 2022-11-12 17:47:41 -08:00
misc Added vhs tape 2022-11-12 18:16:35 -08:00
.editorconfig Added metafiles 2022-10-20 11:01:50 -07:00
.gitignore Added vhs tape 2022-11-12 18:16:35 -08:00
LICENSE Cleanup & build files 2022-10-21 21:01:06 -07:00
README.md Updated README 2022-11-12 18:07:04 -08:00
macros.lamb Fixed a macro bug 2022-11-09 21:44:32 -08:00
pyproject.toml Notes 2022-11-11 18:32:40 -08:00
setup.py Cleanup & build files 2022-10-21 21:01:06 -07:00

README.md

Lamb: A Lambda Calculus Engine

If you're reading this on PyPi, go here.

Lamb demo

Installation

Method 1: PyPi here

  1. pip install lamb-engine
  2. lamb

Method 2: Git

  1. Clone this repository.
  2. Make and enter a virtual environment.
  3. cd into this directory
  4. Run pip install .
  5. Run lamb

Usage

Type lambda expressions into the prompt, and Lamb will evaluate them.
Use your \ (backslash) key to type a λ.
To define macros, use =. For example,

==> T = λab.a
==> F = λab.a
==> NOT = λa.a F T

Note that there are spaces in λa.a F T. With no spaces, aFT will be parsed as one variable.
Lambda functions can only take single-letter, lowercase arguments. λA.A is not valid syntax.
Free variables will be shown with a ', like a'.

Macros are case-sensitive. If you define a macro MAC and accidentally write mac in the prompt, mac will become a free variable.

Numbers will automatically be converted to Church numerals. For example, the following line will reduce to T.

==> 3 NOT F

If an expression takes too long to evaluate, you may interrupt reduction with Ctrl-C.
Exit the prompt with Ctrl-C or Ctrl-D.

There are many useful macros in macros.lamb. Download the file, then load them with the :load command:

==> :load macros.lamb

You can also pass files to lamb directly to have them loaded at startup:

lamb file1 file2

Use your up/down arrows to recall history.

Have fun!


Commands

Lamb understands many commands. Prefix them with a : in the prompt.

:help Print a help message

:clear Clear the screen

:rlimit [int | None] Set maximum reduction limit. :rlimit none sets no limit.

:macros List macros.

:mdel [macro] Delete a macro

:delmac Delete all macros

:step [yes | no] Enable or disable step-by-step reduction. Toggle if no argument is given. When reducing by steps, the prompt tells you what kind of reduction was done last:

  • M: Macro expansion
  • C: Church expansion
  • H: History expansion
  • F: Function application

:expand [yes | no] Enable or disable full expansion. Toggle if no argument is given. If full expansion is enabled, ALL macros will be expanded when printing output.

:save [filename]
:load [filename]
Save or load macros from a file. The lines in a file look exactly the same as regular entries in the prompt, but can only contain macro definitions. See macros.lamb for an example.


Todo:

  • Prevent macro-chaining recursion
  • Cleanup warnings
  • Truncate long expressions in warnings
  • Loop detection
  • α-equivalence check
  • Unchurch command: make church numerals human-readable
  • Better Syntax highlighting
  • Complete file names and commands
  • Tests