esolang

Left-or-right

Every arrow is a value and an operator at once. The middle one of three says which neighbour wins.

xnor, 2020 · Turing complete: no · ●○○ easy · esolangs.org

Tested with 4 known programs · Test method

Run it

Expected: >

The idea

xnor made up Left-or-right, in 2020. There are only two symbols, < and >, and parentheses. In A<B the arrow in the middle points left, so the value is A. In A>B it points right, so the value is B. The items on either side are arrows too, which makes ><> equal to >.

Read the story

A group in parentheses stands for its value, even in the middle place. There is no input, no loop and no memory, so every program stops and prints one character.

The machine

ItemValue
< or > aloneItself
A<BA, the left item
A>BB, the right item
(...)The value of the group inside

A group holds one item or three. The specification never writes any other count, and this implementation stops with an error on one.

Example

In the last one the three groups are worth >, < and <, which leaves ><<.
Expected: <
Expected: >

In the last one the three groups are worth >, < and <, which leaves ><<. Its middle arrow points left, so the answer is the left >.

Patterns it teaches

  • String rewriting: each innermost group of three arrows can be replaced by its value, until one arrow is left.

Further

Also in Rewriting

Write your own in Run Convert a program from Left-or-right

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: left-or-right.

Command line

shib run left-or-right -e '><>'
shib manual left-or-right

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/left-or-right.js

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

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