Functasy
Lambda calculus with numbers for names and no grouping. Every call runs left to right, and one empty function does all the input and output.
Hakerh400, 2019 · Turing complete: yes · ●●● hard · esolangs.org
Tested with 7 known programs · Test method
Run it
The idea
Hakerh400 made Functasy in 2019, after the lambda calculus. A function is written in parentheses, and a number names an argument by how many functions out it belongs to, as de Bruijn indices do. What Functasy takes away is grouping. Elements are applied strictly from left to right. The first is called with the second, the result with the third, and so on.
Read the story
The empty function () is the meta function. It cannot be called. What it does depends on where it stands, and its six cases are the only way to read and write bits, to store a value in an argument or to pass a result on.
The machine
Where () stands | Does |
|---|---|
Alone, (()) | Returns itself |
| First, before an identifier | Writes bit 1; the result is the identifier's value |
| First, before a function | Reads a bit; on 1 calls the function with () |
| Inside, before an identifier | Stores the result in that identifier |
| Inside, before a function | Calls the function with the result |
| Last | Writes bit 0 |
An identifier that holds () counts as () in these cases. The specification gives a JavaScript interpreter of 42 lines that keeps tail calls from growing, and this implementation follows it step by step.
Input and output are bits, in the author's own format. Each input byte becomes 8 bits, lowest first, each after a 1, and a 0 marks the end. Output bits fill bytes from the lowest bit up.
Example
The identity (0) comes first.
The identity (0) comes first. Each function after it writes one bit and hands its argument on, so the chain writes the 8 bits of A, 65, lowest first.
The cat and Hello world. It copies the input bit by bit until the 0 that ends it, then writes 102 more bits. The last 6 are the low bits of the exclamation mark, and filling the byte with 0 completes it.
Patterns it teaches
- Lambda encoding: functions all the way down, with numbers for names.
- Encoding tricks: one byte of input becomes 16 bits, so a program can tell where the input ends.
Further
See also
Functional paradigm
Write your own in Run Convert a program from Functasy
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: functasy.
Command line
shib run functasy -e '()()' --input 'a'shib manual functasySource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/functasy.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org