LAST
Lambda calculus in four letters. There are no variables, only T for the nearest binding and S to skip one.
2022 · Turing complete: yes · ●●● hard · esolangs.org
Tested with 2 known programs · Test method
Run it
The idea
LAST writes lambda calculus with four symbols and no names or numbers. It comes from Binary lambda calculus, where a variable is a de Bruijn index, the number of λs between it and its binding. LAST writes index n as n times S and then T, so index 0 is T and index 2 is SST. The specification calls S the successor.
Read the story
The twist is that S may stand in front of any term, not just T. That term is then evaluated one binding further out. A term can then skip a binding once instead of in every variable, which the specification calls S-optimization. λx.λy.λz.x x x x is LLLAAASSTSSTSSTSST in 18 digits, and LLLSSAAATTTT in 12.
The machine
| Digit | Is |
|---|---|
L | λ, an abstraction of the term after it |
A | The first term after it applied to the second |
T | The value of the nearest binding |
S | The term after it, evaluated one binding further out |
As digits L, A, S and T are 0 to 3, so a program is a number in base 4, and LAST-B writes each digit as two bits. I/O works as in BLC. The program is the first term of the source, the digits after it are its input as a list, and the result is printed as a list of digits. The specification does not say how a digit is a term, so its self-interpreter decides. A digit picks one of four arguments, L the first and T the last, and a list is BLC's pairs.
Example
The example from the specification.
The example from the specification. LT is the identity, and the digits after it are its input.
λx.λy.λz.x x x x and its S-optimized form, each applied to three identities, give the identity, which then prints the rest.
The self-interpreter is 97 digits, 194 bits as LAST-B. It reads a term from its input and hands it to a continuation, which the specification leaves out. Given λt.λr.t nil r, written LLAASTLLTT, it runs the example above.
Patterns it teaches
- Lambda encoding: a digit is a choice among four, a list is pairs.
- Metacircular interpreter: LAST in 97 digits of LAST.
- Encoding tricks: S-optimization, and indices in base 4.
Further
See also
Functional paradigm
Write your own in Run Convert a program from LAST
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: last.
Command line
shib run last -e 'LT' --input 'LALALA'shib manual lastSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/last.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org