Funciton
Programs drawn with box-drawing characters. Boxes are functions, lines carry numbers, and the one loose wire is the output.
Timwi, 2011 · Turing complete: yes · ●●● hard · esolangs.org
The idea
Timwi made Funciton in 2011. A program is a diagram, drawn with the Unicode box-drawing characters (│ ─ ┌ ┐ ╔ ╗ ┬ ┴ …). Lines carry values from one place to another. Boxes are functions you declare and call. There is no instruction pointer at all: the program is a dataflow graph, and the interpreter evaluates whatever the output needs.
Read the story
The only data type is the integer, of any size. Everything else is built on top of it. A string is one big integer, 21 bits per character, first character in the lowest bits. A list or lazy sequence is a lambda that, when asked, returns a head and a tail. Since elements are computed only when asked for, sequences can be infinite.
The specification makes a point of it: this is not electronics. It looks like a circuit, but it is a function graph, and the diagrams mean the same rotated by 90 degrees.
The machine
The built-in operations are deliberately few:
| Primitive | What it is |
|---|---|
| NAND | A T-junction where two lines meet head-on and one leaves sideways |
| Splitter | The same junction with the directions reversed: one value copied to two lines |
| Less-than | A comparison of two integers |
| Shift-left | Shift one integer left by another |
| Input | An empty double-lined box: all of standard input, as one string-integer |
| Lambda | Make a function value, and call it |
| Function call | A box with the declared function's name inside |
Arithmetic, strings, lists and sequences are written in Funciton from these. A double-lined box with a number inside is a constant. The program's single dangling line is its output, printed as a string.
Example
These two come from the specification and show the shape of things.
These two come from the specification and show the shape of things. The diagrams have not been run.
A constant wired to the output. 47 is the code of /, so this prints /:
╔════╗
║ 47 ║
╚═╤══╝
│
cat: an empty double-lined box is standard input, wired straight to the output.
╔═══╗
║ ║
╚═╤═╝
│
To print Hi you would put one number in the box: H is 72 and i is 105, so the string is 72 + 105 × 2²¹ = 220,201,032.
Patterns it teaches
- Two-dimensional control flow: it is really dataflow. There is no "where am I now", only "what feeds what".
- Encoding tricks: strings are integers, 21 bits per character, and the empty string is 0.
- Lambda encoding: lists and lazy sequences are lambdas that return a head and a tail, the same idea as Church-style pairs.
Try this
- Work out the integer that prints
Hey(three characters, 21 bits each). - Using only NAND and a splitter, how would you build NOT? (One NAND whose two inputs are the same value.)
- Hard: read the "logic gates" section of the specification and build XOR from NANDs on paper.
Further
- esolangs.org/wiki/Funciton, with diagrams of every primitive.
- Timwi's interpreter and standard library, linked from the specification.
- Related: Marbelous, another language where values travel through a drawn machine.
See also
Declarative paradigm
Two-dimensional languages
Source esolangs.org (CC0) · Edit on esolangs.org