2023-04-02 07:55:37 -07:00
# 🐑 Lamb: A Lambda Calculus Engine
2022-10-21 15:07:38 -07:00
2023-01-09 17:15:52 -08:00
- [Primary Repo ](https://git.betalupi.com/Mark/lamb )
- [Github Mirror ](https://github.com/rm-dr/lamb )
2022-11-11 18:19:38 -08:00
2022-11-12 18:56:29 -08:00
![Lamb demo ](https://betalupi.com/static/git/lambdemo.gif )
2022-10-21 15:07:38 -07:00
2022-11-11 18:19:38 -08:00
2023-04-02 07:55:37 -07:00
## :brain: What is lambda calculus?
2022-10-21 15:07:38 -07:00
2023-04-02 07:55:37 -07:00
- [video 1 ](https://www.youtube.com/watch?v=3VQ382QG-y4 ): Introduction and boolean logic. The first few minutes are a bit confusing, but it starts to make sense at about [`6:50` ](https://youtu.be/3VQ382QG-y4?t=400 )
- [video 2 ](https://www.youtube.com/watch?v=pAnLQ9jwN-E ): Continuation of video 1. Features combinators and numerals.
- [blog ](https://www.driverlesscrocodile.com/technology/lambda-calculus-for-people-a-step-behind-me-1 ): Another introduction. Moves slower than the two videos above and doesn't assume CS knowledge. Four-part series.
2023-10-16 15:31:49 -07:00
- [handout ](https://static.betalupi.com/ormc/Advanced/Lambda%20Calculus.pdf ): A handout I've written on lambda calculus. Solutions are available through a link elsewhere on this site,you'll have to find them yourself.
2023-04-02 07:55:37 -07:00
## :package: Installation
2022-11-12 18:56:29 -08:00
### Method 1: [PyPi](https://pypi.org/project/lamb-engine)
2023-03-30 20:29:29 -07:00
1. *(Optional but recommended)* make and enter a [venv ](https://docs.python.org/3/library/venv.html )
- **On Windows, run the following in cmd or powershell:**
- `cd Desktop`
- `python -m venv lamb`
- `.\Scripts\activate`
2022-11-12 18:56:29 -08:00
2. `pip install lamb-engine`
3. `lamb`
2022-10-28 20:45:39 -07:00
### 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 .``
2022-11-11 18:19:38 -08:00
5. Run ``lamb``
2022-10-28 20:45:39 -07:00
-------------------------------------------------
2023-04-02 07:55:37 -07:00
## 📖 Usage
2022-10-28 20:45:39 -07:00
2022-11-07 19:58:11 -08:00
2023-04-02 07:55:37 -07:00
Type expressions into the prompt, and Lamb will evaluate them. \
2022-10-28 20:45:39 -07:00
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` .
2022-11-11 18:19:38 -08:00
There are many useful macros in [macros.lamb ](./macros.lamb ). Download the file, then load them with the `:load` command:
2022-11-07 19:58:11 -08:00
```
==> :load macros.lamb
```
2022-11-11 18:31:37 -08:00
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.
2022-11-11 17:04:05 -08:00
2022-11-07 19:58:11 -08:00
Have fun!
2022-10-28 20:45:39 -07:00
-------------------------------------------------
2023-04-02 07:55:37 -07:00
## :card_file_box: Commands
2022-10-28 20:45:39 -07:00
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
2022-11-11 18:31:37 -08:00
`:help` Print a help message
2022-10-28 20:45:39 -07:00
`:clear` Clear the screen
`:rlimit [int | None]` Set maximum reduction limit. `:rlimit none` sets no limit.
2022-11-11 18:31:37 -08:00
`:macros` List macros.
2022-10-28 20:45:39 -07:00
`:mdel [macro]` Delete a macro
2022-11-11 18:31:37 -08:00
`:delmac` Delete all macros
2022-11-11 17:04:05 -08:00
`: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
2022-11-11 15:45:22 -08:00
`: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.
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
-------------------------------------------------
## Todo:
2022-11-11 17:07:45 -08:00
- Prevent macro-chaining recursion
2022-11-09 21:47:55 -08:00
- Cleanup warnings
2022-11-09 21:54:10 -08:00
- Truncate long expressions in warnings
2022-10-29 10:25:06 -07:00
- Loop detection
2022-11-11 18:19:38 -08:00
- α -equivalence check
2022-11-07 20:18:33 -08:00
- Unchurch command: make church numerals human-readable
2023-04-02 07:55:37 -07:00
- Better syntax highlighting
- Tab-complete file names and commands
- Load default macros without manually downloading `macros.lamb` (via `requests` , maybe?)
2022-11-01 20:48:43 -07:00
- Tests