This repository has been archived on 2024-11-05. You can view files and clone it, but cannot push or open issues/pull-requests.
lamb/README.md

103 lines
2.8 KiB
Markdown
Raw Normal View History

2022-10-21 15:10:36 -07:00
# Lamb: A Lambda Calculus Engine
2022-10-21 15:07:38 -07:00
2022-10-28 20:45:39 -07:00
![Lamb screenshot](./misc/screenshot.png)
2022-10-21 15:07:38 -07:00
2022-10-28 20:45:39 -07:00
## Installation
2022-10-21 15:07:38 -07:00
2022-10-28 20:45:39 -07:00
### Method 1: PyPi (not yet)
1. Put this on PyPi
2. Write these instructions
### Method 2: Git
1. Clone this repository.
2. Make and enter a [virtual environment](https://docs.python.org/3/library/venv.html).
3. ``cd`` into this directory
4. Run ``pip install .``
5. Run ``python .``
-------------------------------------------------
## Usage
2022-11-07 19:58:11 -08:00
2022-10-28 20:45:39 -07:00
Type lambda expressions into the prompt, and Lamb will evaluate them. \
Use your `\` (backslash) key to type a `λ`. \
To define macros, use `=`. For example,
```
2022-11-01 21:33:01 -07:00
==> T = λab.a
==> F = λab.a
==> NOT = λa.a F T
2022-10-28 20:45:39 -07:00
```
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. \
2022-11-07 19:58:11 -08:00
Free variables will be shown with a `'`, like `a'`.
2022-10-28 20:45:39 -07:00
2022-11-07 19:58:11 -08:00
Macros are case-sensitive. If you define a macro `MAC` and accidentally write `mac` in the prompt, `mac` will become a free variable.
2022-10-28 20:45:39 -07:00
Numbers will automatically be converted to Church numerals. For example, the following line will reduce to `T`.
```
2022-11-01 21:33:01 -07:00
==> 3 NOT F
2022-10-28 20:45:39 -07:00
```
2022-11-07 19:58:11 -08:00
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](./macros.lamb). Load them with the `:load` command:
```
==> :load macros.lamb
```
Have fun!
2022-10-28 20:45:39 -07:00
-------------------------------------------------
## Commands
2022-11-07 19:58:11 -08:00
Lamb understands many commands. Prefix them with a `:` in the prompt.
2022-10-28 20:45:39 -07:00
`:help` Prints a help message
`:clear` Clear the screen
`:rlimit [int | None]` Set maximum reduction limit. `:rlimit none` sets no limit.
`:macros` List macros in the current environment.
`:mdel [macro]` Delete a macro
2022-11-07 19:02:27 -08:00
`:clearmacros` Delete all macros
2022-11-07 19:58:11 -08:00
`: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](./macros.lamb) for an example.
2022-10-28 20:45:39 -07:00
-------------------------------------------------
2022-11-01 20:48:43 -07:00
## Todo (pre-release, in this order):
2022-11-09 21:54:10 -08:00
- Fix unique bound variable printer
2022-10-28 20:45:39 -07:00
- Prevent macro-chaining recursion
2022-10-29 10:25:06 -07:00
- Full-reduce option (expand all macros)
- step-by-step reduction
2022-11-01 20:48:43 -07:00
- Update screenshot
2022-11-07 20:18:33 -08:00
- Update documentation
- Write "how it works"
2022-10-22 08:28:05 -07:00
- PyPi package
2022-10-28 20:45:39 -07:00
## Todo:
2022-11-09 21:47:55 -08:00
- Cleanup warnings
- Syntax highlight printouts
2022-11-09 21:54:10 -08:00
- Truncate long expressions in warnings
2022-11-07 20:18:33 -08:00
- History queue + indexing
- Show history command
2022-10-29 10:25:06 -07:00
- Loop detection
2022-11-09 21:44:58 -08:00
- Optimization: reduction can be slow with large trees.
2022-10-28 20:45:39 -07:00
- $\alpha$-equivalence check
2022-11-07 20:18:33 -08:00
- Command-line options (load a file)
- Unchurch command: make church numerals human-readable
- Better Syntax highlighting
2022-11-09 21:44:58 -08:00
- Complete file names and commands
2022-11-01 20:48:43 -07:00
- Tests