esolang

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

Expected: Hello World!

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

CharGoingDoes
~The beam starts here, going right
` | any | End
/ \anyMirrors
^ V < >anyPoint the beam
&anyTake the colour or brightness from a variable
@ + - $upSet the colour, append a character, drop the last one, store it
@ + - * % $downSet, add, subtract, multiply, divide the brightness, store it
@ $leftPrint the colour or the brightness
= :leftRead a character or a line into the colour
\|rightUp, on or down as the brightness is more, equal or less
-rightUp if the colour is the character on the right, else down
{ ( [ ]rightWhile, 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.

Expected: 42
Expected: meow

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.

Expected: 0

Patterns it teaches

Further

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 laser

Source

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