Set
- This article is about Sept 25th 2016's esolang Set. The older Set language is now called Recurl.
Paradigm(s) | imperative |
---|---|
Designed by | u/qwertyu63 (Reddit) |
Appeared in | 2016 |
Type system | weak |
Memory system | variable-based |
Dimensions | one-dimensional |
Computational class | Turing complete |
Reference implementation | set-lang (GitHub) |
Influenced | A IS B |
File extension(s) | .set |
Set is an esolang with only one command: "Set". It also supports conditional statements and variable assignments. Output is ASCII-based. Set's tagline is The Set programming language - only one command, endless possibilities! Set is based off the original specification by Reddit user qwertyu63. Initial development by Matheus Avellar.
Variables
Set supports 52 assignable variables. Each variable is a single upper or lower case letter and stores a single unbounded integer.
All lower case variables are initialized to 0; all upper case variables are initialized to their ASCII representation (65-90).
There is also a special system variable indicated by a question mark (?
), which contains the line of code currently being executed.
Commands (set A B
)
As previously estabilished, there is only 1 command in Set: set A B
.
Each set
command must be on its own line, and is case insensitive.
set
takes two arguments, each separated by 1 space (set█A█B
):
A
must be either a variable or an exclamation point.B
must be either a variable, an exclamation point, a combiner or an integer.
On most occasions, the set
command will set the variable on argument A
to the value of argument B
.
Example:
set k 10 > Assigns 10 to the variable 'k' set a A > Assigns ASCII value of 'A' (65) to the variable 'a'
Exclamation point (!
)
Exclamation points indicate input/output. When used as argument:
A
: Outputs the ASCII character matching argumentB
to the screen.B
: Takes one ASCII character as input and sets argumentA
to the matching integer.
Example:
> When used as argument "A" set ! A set ! B > Outputs: AB > When used as argument "B" set a ! > Prompts the user for a one-character-long value input > and assigns it to the variable 'a' set b ! > Received "B" > 'b' now equals 66
Question mark (?
)
Question marks represent the line of code which is being executed. When used as argument:
A
: Works as a 'go to' function. Defines the value ofB
as the line of code to be executed nextB
: Acts as a regular variable. Assigns argumentA
the number of the current line of code
Example:
set a ? > Defines 'a' as 1 set ? 1 > Jumps to line 1, thus creating an infinite loop set z 1 > This line will never be executed, as the code cannot reach it
Combiners ((N+M)
)
Combiners allow you to combine two numbers into one. There are two valid combiners; each used in the place of argument B
:
(N+M)
: is equal toN
plusM
.(N-M)
: is equal toN
minusM
.
N
and M
must be either a variable or a single digit integer.
Example:
set b (A+1) > Adds 1 to ASCII value of 'A' (65) > b becomes 66 (ASCII for 'B')
Conditionals ([X=Y]
)
By putting a conditional in front of a set
command, you can make that command only run in some situations. There are two valid conditionals:
[X/Y]
:X
must not equalY
.[X=Y]
:X
must equalY
.
If the condition is not met, the command is not run. X and Y must be either a variable or a single digit integer.
Example:
set a 1 [a=0] set a 2 > If 'a' equals 0, then set 'a' to 2 [a/0] set a 3 > If 'a' is not equal to 0, then set 'a' to 3 > 'a' is 3
Comments
Although not specified in the original concept of the Set language,
the >
(greater than) character may be used to insert comments on the Set code.
Example:
> Whole line comment. Starts with a '>' symbol. This line is completely ignored by the parser. set a 10 > Inline comment. Starts after a 'set' command, which runs normally. set b 20 > By convention, inline comments should always be separated of > the 'set' command by at least 2 spaces
Computational class
Set is Turing complete, as any 2-counter Minsky machine can be converted to an equivalent Set program. Use of the +
and -
combiners, along with conditionals, allows for unconditional increment and conditional decrement to be implemented. Loops and control flow can be achieved with the ?
variable.
Example code
Hello world!
Here is a 97 bytes example of a "Hello world!" program in Set:
set ! H set ! E set ! L set ! L set ! O set ! 32 set ! W set ! O set ! R set ! L set ! D set ! 33
Outputs:
HELLO WORLD!
99 Bottles of Beer
A 932 bytes "99 Bottles of Beer" program in Set:
set l 10 set s 32 set m 44 set t 48 set a 57 set b 57 set e (a-c) set f (b-d) [i=4] set i 0 set ! e set ! f set ! s set ! B set ! O set ! T set ! T set ! L set ! E set ! S set ! s set ! O set ! F set ! s set ! B set ! E set ! E set ! R [i=1] set ? 49 set ! s set ! O set ! N set ! s set ! T set ! H set ! E set ! s set ! W set ! A set ! L set ! L set ! l [k=1] set ? 97 [i=3] set i 4 [i=4] set ! l [i=4] set ? 9 [i/2] set i 1 [i=1] set ? 9 [i=2] set ? 87 set ! l set ! T set ! A set ! K set ! E set ! s set ! O set ! N set ! E set ! s set ! D set ! O set ! W set ! N set ! m set ! s set ! P set ! A set ! S set ! S set ! s set ! I set ! T set ! s set ! A set ! R set ! O set ! U set ! N set ! D set ! l set i 2 [d=9] set d l [d/l] set d (d+1) [d=l] set c (c+1) [d=l] set d 0 set e (a-c) set f (b-d) [e=f] set ? 93 [c=l] set ? 91 [i=2] set i 3 [i=3] set ? 9 [d=l] set ? 93 [d/l] set ? 88 [e=t] set ? 95 set ? 88 set k 1 set ? 9 > EOF
Outputs:
99 BOTTLES OF BEER ON THE WALL 99 BOTTLES OF BEER TAKE ONE DOWN, PASS IT AROUND 98 BOTTLES OF BEER ON THE WALL ... 01 BOTTLES OF BEER ON THE WALL 01 BOTTLES OF BEER TAKE ONE DOWN, PASS IT AROUND 00 BOTTLES OF BEER ON THE WALL
Truth Machine
A small truth machine in Set.
set a ! set b 6 set a (a-8) set b (b-1) [b/0] set ? 3 [a=0] set ! 48 [a/0] set ! 49 [a/0] set ? 7