Backhand
A one-line program read three cells at a time, bouncing back and forth off its ends like a ball.
Jo King, 2018 · Turing complete: unknown · ●●○ moderate · esolangs.org
Tested with 6 known programs · Hello World on Try It Online: identical · Test method
Run it
The idea
Jo King made Backhand in 2018, after 2D languages like ><> and Befunge, but with only one dimension. The pointer does not read the line in order. It starts on the first character and jumps three cells at a time, and when a jump would leave the line it bounces back off the end. So 1O+1@ runs as 1 1 + O @.
Read the story
The name comes from "back and forth". Programs fold over themselves: the Hello World is the text of the message in a scrambled order that the bouncing reads straight.
The machine
Two stacks of integers (an empty one pops 0), a register and a step size that starts at 3.
| Char | Does |
|---|---|
0-9 a-f " ' | Push a number, a string, or the next character |
~ $ : & r l | Drop, swap, dup, register, reverse, length |
( ) x | Pull from the other stack, push onto it, swap the two |
< > | Move left or right |
{ } | Move one cell left or right instead of a full step |
^ M v W | Step size up by 1 or 2, down by 1 or 2 |
_ \| | Pop: one cell right if 0 else left; reverse if not 0 |
! L G E | Not, less, greater, equal |
+ - * / % [ ] | Arithmetic, decrement, increment |
i o I O | Read and write a character or a number |
H h @ | Print the stack as text and stop, print the top and stop, stop |
Example
The Hello World from the specification.
The Hello World from the specification. " turns on string mode, and the pointer collects the letters as it bounces: ! d l r o W going right, then back the other way. H prints the stack from the top.
A cat. { at the start bounces the pointer back onto i. Each turn reads a byte, keeps a copy one higher, and | turns around on anything but the end of input, through o and back to i.
A factorial, and a quine.
Patterns it teaches
- Two-dimensional control flow squeezed into one line: bouncing gives three interleaved passes over the same code.
- Stack machines: two stacks and a register, as in Brain-Flak.
- Quine: the code is read in a different order than it is written, and still prints itself.
Further
- esolangs.org/wiki/Backhand
- The interpreter, in Python
See also
Self-modifying
Stack-based
Write your own in Run Convert a program from Backhand
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: backhand.
Command line
shib run backhand -e 'I|@}: O' --input '0'shib manual backhandSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/backhand.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org