esolang

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

Expected: Hello, World!

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.

CharCardinalOrdinal
/ \Turn 45 degrees and switch modethe same
_ \|WallsWalls
"Record cells, push them as integersRecord cells, push them as one string
0-9Push a digitAppend a digit to a string
+ - * : %Add, subtract, multiply, divide, moduloSuperimpose, remove, join, find, split
i I o ORead a byte or a character, write oneRead all or a line, write a string or a line
R h tNegate, increment, decrementReverse, head, tail
! ? [ ]Tape of integersThe same tape read as words
< > ^ vArrowsHalf walls that only fix one component
$ =Skip if 0, turn by the signSkip if empty, turn by comparing
&Run the next command n timesRun it once per character
j k wJump to x, y, return, push a return addressthe same
@EndEnd

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.

Expected: Hi!
Expected: 7

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

Further

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 alice

Source

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