esolang

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

Expected: 362880

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

StatementDoes
print xPrint a value and a line feed
a = xAssign; += -= *= /= %= work too
a ++ a --Add or subtract 1
if condRun the lines up to } when cond is true
loopRun an initial statement, then the lines up to } and a step while a condition holds
asCode xTurn the string x into code
userInputRead 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.

Expected: 25

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.

Expected: 0 1 2
Expected: 14

Patterns it teaches

  • Code as data: names and whole programs are built as strings and run with asCode.

Further

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-array

Source

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