esolang

Goto Considered Harmless

Seven commands, and the only way to branch is a jump through the program's own text.

Ninesquared81, 2023 · Turing complete: unknown · ●●○ moderate · esolangs.org

Tested with 2 known programs · Test method

Run it

Expected: 5

The idea

Ninesquared81 made Goto Considered Harmless in 2023, and named it after its one control flow construct, a conditional jump. Memory is an unbounded row of signed 64-bit cells. Both pointers are in the programmer's hands. ip points into the source text and dp into the cells.

Read the story

The jump is relative and counts characters, not commands. So every character matters, even the ones that do nothing. The truth machine needs a space on its second line just to have something to jump over.

The machine

CharDoes
?If the cell is 0, move dp right; otherwise move ip by the cell's value
<Swap the cell with the one before it, then move dp left
+ -Add dp to the cell, or take it away
,Read a character into the cell
. #Print the cell as a character, or as a number

After every character ip moves on by one, so a jump of n lands n + 1 characters further on. A jump below the start goes back to the first character, and a jump past the end stops the program.

There are no constants. A number comes from walking dp to it over zero cells and adding dp.

Example

Five ?

Five ? on zero cells walk dp to 5, and + adds 5 to that cell.

The truth machine. Its 48 ? walk dp to cell 48, where the input character goes and 48 is taken away. On 0 it walks on to cell 61, puts 61 there and jumps out of the program.

Expected: 0

On 1 the 43 < carry the 1 down to cell 5. There -+#-? prints it, leaves -4 and jumps back to the +, which brings back the 1, and so it prints 1 for ever.

Further

Cell-based

Write your own in Run Convert a program from Goto Considered Harmless

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: goto-considered-harmless.

Command line

shib run goto-considered-harmless -e '????????????????????????????????????????????????,-#
?????????????+? <<<<<<<<<<<<<<<<
<<<<<<<<<<<<<<<<<<<<<<<<<<<-+#-?' --input '0'
shib manual goto-considered-harmless

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/goto-considered-harmless.js

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

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