esolang

Lamp

Every value is on or off. There is no if, only circuits that run when a lamp powers them.

2021 · Turing complete: unknown · ●○○ easy · esolangs.org

Tested with 5 known programs · Test method

Run it

Expected: on

The idea

Lamp is an imperative language from 2021 in which every value is on or off. A lamp holds one of them. A switch has exactly two positions, called off and on, and each position holds a lamp value or another switch, so switches nest into lists and trees.

Read the story

Code is split into circuits, which end with ground. A circuit runs when it is powered, and power c x powers it only when x is on. That is the whole conditional. A circuit may power itself, and it can be defined anywhere in the file, even after the line that powers it.

The machine

StatementDoes
lamp x onMake a lamp
switch s (on (off on))Make a switch; s.off is on, s.on.off is off
switch t s.onCopy part of a switch
display xWrite on or off for each lamp
display block xWrite a block for on and a space for off
circuit c ... groundDefine a circuit
power c xRun c when x is on; -x is not x
delete switch sRemove a switch

Names may carry a namespace, as in ns:x. A lamp without one lives in lamp: and a switch in switch:. Circuits have no scope of their own, so a namespace is how a circuit keeps its lamps apart.

Example

An if and an else are two circuits, one powered by a lamp and one by its negation.
Expected: █ ██
Expected: on off

An if and an else are two circuits, one powered by a lamp and one by its negation.

Expected: █

A program for the word lamp keeps one switch of 19 lamps per row and displays the five rows in blocks.

█     ██  █  █ ████
█    █  █ ████ █  █
█    █  █ █  █ ████
█    ████ █  █ █
████ █  █ █  █ █

Further

Also in Turing tarpits

Write your own in Run Convert a program from Lamp

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: lamp.

Command line

shib run lamp -e 'lamp example on
display example'
shib manual lamp

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/lamp.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org