esolang

Mirror

A language that mirrors a command each time it passes over it.

alexander-liao · Turing complete: no · ●○○ easy · esolangs.org

Tested with 4 known programs · Hello World on Try It Online: identical except the line end · Test method

Run it

Expected: Hello, World!

The idea

Every command has an inverse, and each time the pointer passes over a command, the command turns into it. + becomes -, , (read) becomes . (print), and back again on the next pass. The pointer walks the first line of the program to the right, round and round, until it meets @.

Read the story

This is the language TIO runs as Mirror, from alexander-liao's repository. The MIRROR page on esolangs.org describes a different language.

The machine

A stack of values. This implementation follows the Python interpreter, which is unfinished, and keeps what it does.

CommandDoesBecomes
0-9Push the digit
"text"Push the string, with Python's escapes
,Read a line.
.Pop and print it with a newline,
+ -Pop two values- +
!Jump over the next cell, which becomes !!
@End, printing the bottom of the stack

In the interpreter + and - only work on lists, which no command makes, so they leave None on the stack. . leaves a None too. Lines after the first never run.

Example

The second program prints the line it reads, then @ prints the None that .
Expected: echo None

The second program prints the line it reads, then @ prints the None that . left on the stack.

Patterns it teaches

Further

Two-dimensional languages

Stack-based

Write your own in Run Convert a program from Mirror

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: mirror.

Command line

shib run mirror -e '3.@'
shib manual mirror

Source

Module
langs/tio/ports.js
Interpreter
langs/tio/mirror.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org