Laser
A beam of light with a colour and a brightness. What a mirror or a sign does depends on which way the beam is going.
FizzyApple12 · Turing complete: unknown · ●●○ moderate · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
FizzyApple12 made Laser, a grid language about a laser beam. The beam carries two values, a colour, which is a piece of text, and a brightness, which is a number. Most commands mean something different for each direction the beam travels in. Going up they work on the colour, going down on the brightness, going left they read and print, and going right they branch and loop.
Read the story
A command's operand is the character to its right, even when the beam goes up or down past it. So a column of +l +e +H read from the bottom builds a word.
The machine
| Char | Going | Does |
|---|---|---|
~ | The beam starts here, going right | |
` | any | End | ||
/ \ | any | Mirrors |
^ V < > | any | Point the beam |
& | any | Take the colour or brightness from a variable |
@ + - $ | up | Set the colour, append a character, drop the last one, store it |
@ + - * % $ | down | Set, add, subtract, multiply, divide the brightness, store it |
@ $ | left | Print the colour or the brightness |
= : | left | Read a character or a line into the colour |
\| | right | Up, on or down as the brightness is more, equal or less |
- | right | Up if the colour is the character on the right, else down |
{ ( [ ] | right | While, while and for loops, closed by ] |
Example
The beam goes right from ~ and climbs four columns between the mirrors.
The beam goes right from ~ and climbs four columns between the mirrors. The first column sets the colour to H and appends e and l, and each later column appends three more. At the top right a mirror turns it left onto @, which prints the colour, and ` ends the run.
Going down, the same @ sets the brightness. The beam sets it to 7, multiplies it by 6, and turns left onto $, which prints the brightness.
The cat bends down and left, reads a line with : and prints it with @. The truth machine reads a line and tests it against 0 with -. On 0 the beam goes up to a print and ends. On 1 it enters a loop that prints 1 forever.
Patterns it teaches
- Two-dimensional control flow: the direction of travel picks what each command means.
Further
See also
Two-dimensional languages
Write your own in Run Convert a program from Laser
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: laser.
Command line
shib run laser -e '~ \
`@:/' --input 'meow'shib manual laserSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/laser.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org