Compare commits

...

15 Commits

Author SHA1 Message Date
5bff77e4a7 Merge branch 'master' of https://github.com/rm-dr/lamb 2023-11-27 14:23:00 -08:00
8c8ea69890 Update README.md 2023-11-27 14:21:13 -08:00
6d14333e52 Update README.md 2023-11-27 14:19:24 -08:00
ab9057148a Merge branch 'master' of ssh://git.betalupi.com:33/Mark/lamb 2023-10-17 18:37:38 -07:00
c07edf1b50 Updated README.md 2023-10-16 21:17:27 -07:00
1bb0b91e20 Fixed a link in README 2023-10-16 15:31:49 -07:00
b20604de5c Fixed a path 2023-10-10 22:08:07 -07:00
d2f8b1c8fb Updated version 2023-04-02 20:54:26 -07:00
3022c2ffc0 Removed type hints to support older python versions 2023-04-02 20:52:59 -07:00
acbc247e10 Merge branch 'master' of ssh://git.betalupi.com:33/Mark/lamb 2023-04-02 07:56:55 -07:00
907d2d9e79 Added links to readme 2023-04-02 07:55:37 -07:00
73f4c60c06 Updated install instructions 2023-03-30 20:29:29 -07:00
fe7e6fca13 Added social media banner 2023-01-09 17:36:49 -08:00
866cb64485 Updated links 2023-01-09 17:15:52 -08:00
09a389857a Hide time when reducing by steps 2022-11-12 19:31:12 -08:00
6 changed files with 144 additions and 42 deletions

View File

@ -1,14 +1,27 @@
# Lamb: A Lambda Calculus Engine
# 🐑 Lamb: A Lambda Calculus Engine
If you're reading this on PyPi, go [here](https://git.betalupi.com/Mark/lamb).
![Lamb demo](https://betalupi.com/static/git/lambdemo.gif)
![Lamb Demo](https://github.com/rm-dr/lamb/assets/96270320/d518e344-e7c8-47ed-89c4-7ce273bf4e2d)
## Installation
## :brain: What is lambda calculus?
- [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.
- [handout](https://static.betalupi.com/ormc/Advanced/Lambda%20Calculus.pdf): A handout I've written on lambda calculus.
## :package: Installation
### Method 1: [PyPi](https://pypi.org/project/lamb-engine)
1. *(Optional but recommended)* make and enter a [venv](https://docs.python.org/3/library/venv.html).
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`
2. `pip install lamb-engine`
3. `lamb`
@ -21,10 +34,10 @@ If you're reading this on PyPi, go [here](https://git.betalupi.com/Mark/lamb).
-------------------------------------------------
## Usage
## 📖 Usage
Type lambda expressions into the prompt, and Lamb will evaluate them. \
Type expressions into the prompt, and Lamb will evaluate them. \
Use your `\` (backslash) key to type a `λ`. \
To define macros, use `=`. For example,
```
@ -63,7 +76,7 @@ Have fun!
-------------------------------------------------
## Commands
## :card_file_box: Commands
Lamb understands many commands. Prefix them with a `:` in the prompt.
@ -100,8 +113,7 @@ The lines in a file look exactly the same as regular entries in the prompt, but
- 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
- Better syntax highlighting
- Tab-complete file names and commands
- Load default macros without manually downloading `macros.lamb` (via `requests`, maybe?)

View File

@ -77,8 +77,8 @@ class Node:
self.parent_side: Direction = None # type: ignore
# Left and right nodes, None if empty
self._left: Node | None = None
self._right: Node | None = None
self._left = None
self._right = None
# The runner this node is attached to.
# Set by Node.set_runner()
@ -341,7 +341,7 @@ class Bound(EndNode):
# The name of the macro this bound came from.
# Always equal to self.name, unless the macro
# this came from had a subscript.
self.macro_name: str | None = macro_name
self.macro_name = macro_name
if forced_id is None:
self.identifier = bound_counter
@ -381,9 +381,9 @@ class Func(Node):
Func.from_parse(result)
)
def __init__(self, input: Macro | Bound, output: Node, *, runner = None) -> None:
def __init__(self, input, output: Node, *, runner = None) -> None:
super().__init__()
self.input: Macro | Bound = input
self.input = input
self.left: Node = output
self.right: None = None
self.runner = runner # type: ignore

View File

@ -14,7 +14,7 @@ help_texts = {}
def lamb_command(
*,
command_name: str | None = None,
command_name = None,
help_text: str
):
"""

View File

@ -46,7 +46,7 @@ class Runner:
# Maximum amount of reductions.
# If None, no maximum is enforced.
# Must be at least 1.
self.reduction_limit: int | None = 1_000_000
self.reduction_limit = 1_000_000
# Ensure bound variables are unique.
# This is automatically incremented whenever we make
@ -74,7 +74,7 @@ class Runner:
message = self.prompt_message
)
def parse(self, line) -> tuple[lamb_engine.nodes.Root | MacroDef | Command, list]:
def parse(self, line): # -> tuple[lamb_engine.nodes.Root | MacroDef | Command, list]
e = self.parser.parse_line(line)
w = []
@ -196,24 +196,31 @@ class Runner:
]
else:
if not self.step_reduction:
out_text += [
("class:ok", f"Runtime: "),
("class:text", f"{time.time() - start_time:.03f} seconds"),
("class:text", "\n")
]
out_text += [
("class:ok", f"Runtime: "),
("class:text", f"{time.time() - start_time:.03f} seconds"),
("class:ok", f"\nExit reason: "),
("class:ok", f"Exit reason: "),
stop_reason.value,
("class:text", "\n"),
("class:ok", f"\nMacro expansions: "),
("class:ok", f"Macro expansions: "),
("class:text", f"{macro_expansions:,}"),
("class:text", "\n"),
("class:ok", f"\nReductions: "),
("class:ok", f"Reductions: "),
("class:text", f"{k:,}\t"),
("class:muted", f"(Limit: {self.reduction_limit:,})")
]
if self.full_expansion:
out_text += [
("class:ok", "\nAll macros have been expanded")
("class:text", "\n"),
("class:ok", "All macros have been expanded")
]
if (

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 30 KiB

View File

@ -15,7 +15,7 @@ lamb = "lamb_engine:main"
[project]
name = "lamb_engine"
description = "A lambda calculus engine"
version = "1.1.7"
version = "1.1.9"
dependencies = [
"prompt-toolkit==3.0.31",
"pyparsing==3.0.9"