Alice
Two languages on one grid. Moving straight it works on integers, moving diagonally on strings.
Martin Ender, 2017 · Turing complete: yes · ●●● hard · esolangs.org
Tested with 8 known programs · Hello World on Try It Online: identical except the line end · Test method
Run it
The idea
Martin Ender made Alice in 2017, with a lot of help from Sp3000. It is a Fungeoid with a twist on mirrors. In most 2D languages a mirror turns the pointer by 90 degrees. In Alice the pointer passes through a mirror and comes out turned by only 45 degrees, so a horizontal path becomes a diagonal one and back.
Read the story
Each mirror also switches the mode. Moving horizontally or vertically the pointer is in Cardinal mode. It wraps around the edges and every command works on integers. Moving diagonally it is in Ordinal mode. It bounces off the edges and the same characters work on strings. + adds two numbers in one mode and superimposes two strings in the other, R negates or reverses.
The machine
One stack holds integers and strings both. Cardinal mode reads the integers out of a string it pops, and Ordinal mode turns a popped integer into its digits. An empty stack gives 0 or the empty string.
| Char | Cardinal | Ordinal |
|---|---|---|
/ \ | Turn 45 degrees and switch mode | the same |
_ \| | Walls | Walls |
" | Record cells, push them as integers | Record cells, push them as one string |
0-9 | Push a digit | Append a digit to a string |
+ - * : % | Add, subtract, multiply, divide, modulo | Superimpose, remove, join, find, split |
i I o O | Read a byte or a character, write one | Read all or a line, write a string or a line |
R h t | Negate, increment, decrement | Reverse, head, tail |
! ? [ ] | Tape of integers | The same tape read as words |
< > ^ v | Arrows | Half walls that only fix one component |
$ = | Skip if 0, turn by the sign | Skip if empty, turn by comparing |
& | Run the next command n times | Run it once per character |
j k w | Jump to x, y, return, push a return address | the same |
@ | End | End |
Example
The Hello World from Try It Online.
The Hello World from Try It Online. The pointer enters the mirror in the top left corner and leaves it going down and right, in Ordinal mode, zigzagging between the two rows. It records Hello, World! and bounces back off a second mirror. O prints the string with a newline and @ ends.
In Cardinal mode a string is a row of character codes. 3& runs o three times.
In the last one 34+ adds in Cardinal mode, the mirror sends the pointer down and right in Ordinal mode, and O prints the 7 as text.
Patterns it teaches
- Two-dimensional control flow: eight directions, and the direction decides what every command means.
- Stack machines: one stack seen as integers or as strings.
Further
- esolangs.org/wiki/Alice
- The reference interpreter, in Ruby, with the full spec
See also
Two-dimensional languages
Stack-based
Write your own in Run Convert a program from Alice
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: alice.
Command line
shib run alice -e '"!iH"3&o@'shib manual aliceSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/alice.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org