Anyfix
A function may stand before, between or after its arguments; it waits until the stack holds enough of them.
HyperNeutrino · Turing complete: unknown · ●●○ moderate · esolangs.org
Tested with 7 known programs · Hello World on Try It Online: identical · Test method
Run it
The idea
Anyfix is a golfing language by HyperNeutrino, inspired by Jelly and 05AB1E. It introduced anyfix notation. A function that finds too few values on the stack does not fail. It joins a queue, and after every token the oldest waiting function that can now run does. So +5 3, 5+3 and 5 3+ all add 5 and 3.
Read the story
The interpreter is written in Python, in the repository alexander-liao/anyfix, and uses SymPy for numbers. This implementation follows its source.
The machine
One stack, with the top as the first argument of a function. The arguments a program is given start on the stack, the first one on top. A function that is still waiting when the program ends never runs.
At the end the whole stack is printed from the top down with nothing between the items. Numbers go through SymPy's floating point form with the trailing zeros cut off, which leaves the point behind, so 55 prints as 55. and one half as 0.5. Lengths are plain Python integers and print without the point.
| Function | Does |
|---|---|
“…” ”c | A string, one character |
+ _ × ÷ | Add, subtract, multiply, divide; the second item with the top |
R Ḷ | The list 1 to n, 0 to n−1 |
S P | Sum and product of a list, or of the whole stack |
D B | Decimal and binary digits |
L | Length |
‘ ’ ² | Add one, take one, square |
Example
The second and third are from esolangs.org.
The second and third are from esolangs.org. R makes the list 1 to 10 and S sums it. D splits 1234 into its digits and S sums those.
In the first one + waits for two values. The last one prints the stack top first.
This implementation is a subset. Codeblocks, lists in brackets and most functions stop the run with a reason. The options Try It Online gives the interpreter are not known, so this implementation uses the interpreter's defaults.
Patterns it teaches
- Code golf: the same function works in any position, so no byte goes to order.
- Stack machines: a queue of waiting functions next to the stack.
Try this
- Multiply 6 and 7 with the function in front.
- Print the number of digits of the input.
- Hard: print the sum of the binary digits of 1 to 10.
Further
- esolangs.org/wiki/Anyfix
- The reference interpreter, in Python
- Related: Enlist, Jelly
See also
Golfing languages
Write your own in Run Convert a program from Anyfix
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: anyfix.
Command line
shib run anyfix -e 'RS' --input '10'shib manual anyfixSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/anyfix.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org