Lightswitch
One keyword, toggle, and a row of switches that are either on or off.
Infinitehexagon, 2023 · Turing complete: no · ●○○ easy · esolangs.org
Tested with 4 known programs · Test method
Run it
The idea
Infinitehexagon made Lightswitch in 2023. All its memory is light switches, named p0, p1, p2 and so on in order, and each one is on or off. The specification writes the two states I and O. A switch can be wired to another, so that toggling the first toggles the second as well.
Read the story
A program runs once from top to bottom. There is no jump and no loop, so the specification calls it clearly not Turing complete.
The machine
| Line | Does |
|---|---|
p0 toggle p1 | Wire p0 to p1; the first line naming a switch brings it in, off |
toggle p0 | Flip p0, and every switch wired to it |
@in p0 | Set p0 to the next input bit |
@out @p p0 | Print the state of p0 as 1 or 0 |
The specification leaves the wiring open. In this implementation a wire passes a toggle on, but a toggle flips each switch only once, so p0 toggle p0 only brings p0 in. That is what the first program in the specification needs, where p0 toggle p0 and then toggle p0 leave p0 on.
Example
The NOT gate reads a bit, flips it and prints it.
The NOT gate reads a bit, flips it and prints it. The cat reads four bits into four switches and prints them back.
A wire makes one toggle flip two switches.
Further
See also
Also in Turing tarpits
Write your own in Run Convert a program from Lightswitch
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: lightswitch.
Command line
shib run lightswitch -e 'p0 toggle p0
@in p0
toggle p0
@out @p p0' --input '0'shib manual lightswitchSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/lightswitch.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org