Anti-Array
No arrays and no stacks. A program makes its own variable names out of strings instead.
Turing complete: unknown · ●●○ moderate · esolangs.org
Tested with 5 known programs · Test method
Run it
The idea
Anti-Array has no arrays or stacks. To keep a hundred values a program makes a hundred variables, var1 to var100, and it gets their names by adding numbers to strings. The command asCode turns a string back into code, so ( asCode ( "{var}" + 1 ) ) is the variable var1.
Read the story
Strings open with "{ and close with }", so they nest. A string can hold a whole program with strings of its own, and asCode runs it later. The specification builds a factorial that works like a function this way. Everything is worked out strictly left to right, so 3 + 4 * 2 is 14.
The machine
| Statement | Does |
|---|---|
print x | Print a value and a line feed |
a = x | Assign; += -= *= /= %= work too |
a ++ a -- | Add or subtract 1 |
if cond | Run the lines up to } when cond is true |
loop | Run an initial statement, then the lines up to } and a step while a condition holds |
asCode x | Turn the string x into code |
userInput | Read a line of input as a number, true, false or a string |
Values are whole numbers, strings and true or false. The operators are + - * / % < > == != and parentheses group. + joins when either side is a string. A | ends a line just as a line break does, which is how a loop puts its start, condition and step on one line. A line that is no statement, such as 2 = 100 or anti array, is ignored.
The interpreter is on GitHub, not in the specification, so a few things are choices of this implementation. print ends with a line feed, numbers have no bounds and division rounds toward 0.
Example
A factorial of 9.
A factorial of 9.
Five variables made from strings, then two of them read back by their names. var3 holds 9 and var4 holds 16.
A loop kept in a string. \n in a string is a line break, and asCode runs a string with line breaks as a program.
Patterns it teaches
- Code as data: names and whole programs are built as strings and run with
asCode.
Further
See also
Also in Hostile
Write your own in Run Convert a program from Anti-Array
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: anti-array.
Command line
shib run anti-array -e 'x = "{loop count = 0 | count < 100 | count ++ |\nprint count\n}}"
asCode x'shib manual anti-arraySource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/anti-array.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org