| Crates.io | troth |
| lib.rs | troth |
| version | 0.1.0 |
| created_at | 2025-05-31 19:11:31.416787+00 |
| updated_at | 2025-05-31 19:11:31.416787+00 |
| description | A Simple λ-Calculus Interpreter |
| homepage | |
| repository | https://github.com/azaleacolburn/troth |
| max_upload_size | |
| id | 1696559 |
| size | 35,132 |
A simple λ-Calculus interpreter
ALIAS: [A-Z0-9_$&+,:=?@#|'<>.-^\*%!]+
ID: [a-km-z_]+
OPAREN: \(
CPAREN: \)
DOT: \.
LAMBDA: l
DEFINITION: fn
USE: use "[a-km-z_\\]+"
SEMI: ;
[!NOTE] Comments are denoted by
//and run until the end of the line Use statements are one token, just like strings are in other languages
definiton: DEFINITION ALIAS expression SEMI
use: USE SEMI
expression: OPAREN (ALIAS | ID | call) CPAREN
call: expression expression
lambda: LAMBDA ID DOT expression
| λ-Calculus Definition | Rust Usage |
|---|---|
fn T lx.ly.x |
true |
fn F lx.ly.y |
false |
fn ! lx.x F T |
!x |
fn & lx.ly.x y x |
x & y |
fn | lx.ly.((x x) y) |
x | y |
fn SUCC lx.ln.lm.(n ((x n) m)) |
x + 1 |
fn 0 ls.lz.z |
0 |
fn 1 SUCC 0 |
1 |
fn + lx.ly.x (SUCC y) |
x + y |
fn * lx.ly.lz.(x (y z)) |
x * y |
fn <=0 lx.(x F) N F |
x <= 0 |
fn >= lx.ly.(Z (x P) y) |
x >= y |
fn >=1 lx.x F N T |
x >= 1 |
[!NOTE] This grammar does support numerical and 'special' characters in (and even as the first character of) ALIASes, meaning full high-level languages could be defined with normal arithmatic. However, IDs must be lowercase alphabetic characters and the '_' character.
Transpilation of λ-calculus to higher-level languages is a uniquely difficult task. Nearly all constructs that are built into other languages, such as number literals, are simply encoded in the λ-calculus. This means that while sometimes certain patterns simply act like their analog in a higher-level language, sometimes they serve completely unrelated purposes. Additionally, there are certain quirks of the λ-calculus, which allow these analogs to have a dual form, such as numerical lliterals, which in their Church-encoded form can be used as definite for-loops as well as number literals. Decyphering this seems impossible algorithmically, thus until future revelations, I will not attempt it.
ALIAS being invoked, it first runs the alias through a an alpha conversion process, where each id within the aliased expression is appended with an alias-specific postfix to avoid conflationdefinitions map into the original parser's map