Beam
A beam of light carries one byte across a grid of mirrors, and a store beside it counts the loops.
Feuermonster, 2012 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 6 known programs · Hello World on Try It Online: identical · Test method
Run it
The idea
Feuermonster thought of Beam around 2010 and published it in 2012. The IP is a beam that holds an 8-bit value. There is no stack. Next to the beam sits the store, a counter that only goes up and down by one, and a row of memory cells the two can reach.
Read the story
Arithmetic is one step at a time, so constants are built with loops: put a count in the store, add to the beam, and let ) turn the beam back while the store is not 0.
The machine
| Char | Does |
|---|---|
> < ^ v | Steer |
/ \ | Mirrors |
! ? | Bounce back if the beam is not 0, or if it is 0 |
\| _ | Bounce a horizontal or a vertical beam |
+ - | Add one to the beam or take one |
@ : | Print the beam as a byte or as a number |
r | Read a byte into the beam (0 at the end) |
S L | Store = beam, beam = store |
' ` | Add one to the store or take one | |
s g | memory[beam] = store, store = memory[beam] |
P p | memory[store] = beam, beam = memory[store] |
u n | Turn up or down if beam and store differ |
) ( | Turn left or right if the store is not 0 |
H | Stop |
Lines are not padded, and a beam that leaves the characters of the program ends the run.
Example
Print a letter with plain counting, then Hello!, which builds each step with a store loop.
Print a letter with plain counting, then Hello!, which builds each step with a store loop.
Read two bytes and print the smaller one, from the specification.
Reverse the input. P writes each byte at memory[store] while the store counts up.
Patterns it teaches
- Two-dimensional control flow: every loop is a loop drawn on the grid.
- Turing completeness: a script in the specification turns any brainfuck program into Beam.
Further
- esolangs.org/wiki/Beam
- beam-js, the interpreter TIO runs
See also
Two-dimensional languages
Cell-based
Write your own in Run Convert a program from Beam
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: beam.
Command line
shib run beam -e '>r@nH
^ <' --input 'abc'shib manual beamSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/beam.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org