esolang

Set

One command, set. Printing, reading, jumping and arithmetic are all just setting something.

qwertyu63, 2016 · Turing complete: yes · ●○○ easy · esolangs.org

Tested with 4 known programs · Hello World on Try It Online: identical · Test method

Run it

Expected: HELLO WORLD!

The idea

Reddit user qwertyu63 proposed Set in September 2016 and Matheus Avellar wrote the first interpreter. Every line is set A B. What that does depends on what A and B are. Setting the variable ! prints, reading from ! takes input, and setting ?, the current line number, is a goto. A condition in front of a line makes it run only sometimes.

The machine

There are 52 variables, one per letter. The lowercase ones start at 0. The uppercase ones start at their own character code, so A is 65 and set ! H prints H.

FormDoes
set a 10Set a variable to a number, a variable or a combiner
set a (b+1) set a (b-c)Combiners: add or subtract two variables or single digits
set ! aPrint a as a character
set a !Read one character into a
set a ?The current line number
set ? 7Jump to line 7
[a=b] set ... [a/b] set ...Run the command only if a equals b, or does not

Lines count from 1, blank lines and comments included. A comment starts with >. The program ends when it runs past its last line or jumps outside it.

Example

The uppercase letters hold their own codes, so they print themselves.

The uppercase letters hold their own codes, so they print themselves. Lowercase letters would need numbers, and that is why the classic hello world shouts.

Expected: 0

A truth machine. Combiners only add single digits, so lines 3 to 5 subtract 8 six times to turn the character 0 (48) into the number 0. Then it prints 0 once, or 1 forever when the input was 1.

Expected: ihi

Two characters read and printed in the other order, then the first one plus 1.

Patterns it teaches

Try this

  1. Print hello in lowercase.
  2. Count from 1 to 9.
  3. Hard: the 99 bottles of beer song. The esolangs.org article has a version in 96 lines.

Further

Also in Turing tarpits

Write your own in Run Convert a program from Set

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run set -e 'set a !
set b !
set ! b
set ! a
set ! (a+1)' --input 'hi'
shib manual set

Source

Module
langs/tio/ports.js
Interpreter
langs/tio/set.js

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

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