esolang

Branch

A tarpit whose memory is a binary tree, walked with slashes and a caret.

HyperNeutrino, 2021 · Turing complete: yes · ●●○ moderate · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: Hello, World!

The idea

HyperNeutrino made Branch in 2021. Its memory is a binary tree of 64-bit integers instead of a tape. / goes to the left child, \ to the right one and ^ to the parent, and a node that is not there yet is made on the way, holding 0. Arithmetic works on a node's two children. + sets a node to the sum of its children, and when a child is missing it first reads that child's value from the input. So +# is a whole program that adds two numbers.

Read the story

There are 26 registers. A to M keep a position and a to m jump back to it. N to Z keep a value and n to z put it back. A starts at the first node, and until a program sets one of A to M itself, the first 12 nodes it makes land in B, C and on.

The machine

CommandDoes
/ \ ^Go to the left child, the right child, the parent
?Go left if the value is 0, else right
" ;Copy the value up to the parent; copy the parent's value down
(Delete this node and all below it, and go up
123Set the value
+ - * : % 'Sum, difference, product, quotient, remainder or power of the two children
& \| < = >And, or and the comparisons of the two children
! _ { }Not, negate, take 1, add 1
# $Print or read a number
. ,Print or read a character
[ ]Loop while the value is not 0
@ ~Start the program again, remembering where; go back there
A to M, a to mKeep the position; go back to it
N to Z, n to zKeep the value; put it back
)End

The specification also has 2-byte built-ins that start with a backtick. Their list is kept on the Branch wiki on GitHub and not in the specification, so this implementation leaves them out.

Example

The Hello World sets each code as a number and prints it with ..
Expected: 28
Expected: 1024

The Hello World sets each code as a number and prints it with .. It keeps 108 in Z and 111 in O and fetches them back with z and o. In the adder the root has no children yet, so + reads both from the input. ' does the same for a power.

The FizzBuzz program builds Fizz and Buzz as chains of left children, one letter a node. It prints a word with [./], which prints a node and steps left until it meets a 0. It prints up to 100, as the specification says it does.

Patterns it teaches

  • Turing tarpit: one-character commands on a tree that grows without end.

Further

Also in Turing tarpits

Write your own in Run Convert a program from Branch

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run branch -e '+#' --input '13 15'
shib manual branch

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/branch.js

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

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