From Esolang
Jump to navigation Jump to search

GetWhen is a terrible unfinished esoteric programming language (it might not even be that esoteric) by User:SoundOfScripting that is designed around code being executed whenever a certain condition is met.

Feel free to edit the language however you want. You can probably definitely make it better than I can.


Programs in GetWhen are a series of lines that each have a line number (starting at 1) before them. Each line has a non-empty list of instructions to be executed. Lines closer to the top of the program take priority.

After a line is executed, the next line will be executed next (unless the instruction pointer is changed). Usually (unless something weird happens), whitespace would be ignored (except for newlines).

Parenthesis are used for function arguments or to control evaluation order.

Whenever // is encountered in a line, the rest of the line is ignored.

Here is a format for valid lines:

<line numbers>: <instructions>

Note: If multiple line numbers or instructions are present, they must be separated by ,s.

Variables and operations

Variable names are a string of alphabetical text. Variables must only store unbounded integers (unless they are undefined, represented by %, which they are until they are set), and there can be as many variables as the program mentions.

The following instructions will set a variable to a value:

x=5                                      //Obviously sets x to 5
y=x                                      //Sets y to x (5)
x=x+7                                    //Sets x to x+7 (5+7 (12))
z=y-x                                    //Sets z to y-x (5-12 (-7))
x=%                                      //Sets x to undefined

The following integer operations are supported (will return undefined if one or more inputs is undefined):

x+y                                      //Sum of x and y
x-y                                      //x minus y
x*y                                      //Product of x and y
x/y                                      //x divided by y, rounded down
x^y                                      //x to the y power
x%y                                      //x mod y     (screw your parsing (just kidding, it shouldn't be that hard))


Here is a list of conditional operators which return a boolean integer (1 for true or 0 for false):

x==y                                     //If x equals y
x!=y                                     //If x is not equal to y
x>y                                      //If x is greater than y
x<y                                      //If x is less than y
x>=y                                     //If x equals y or x is greater than y
x<=y                                     //If x equals y or x is less than y
!<condition>                             //The opposite of some other condition

Note: If either x or y is undefined (%), all conditional operations except for == and != will default to 0 (false).

Instruction pointer

The variable ip is reserved for the instruction pointer, which stores the next line to be executed.

If the instruction pointer is modified in the middle of a line, execution of that line stops and is moved to the line ip was set to.

If the instruction pointer would be set to a line that doesn't exist (this includes undefined), the program terminates.

Built-in functions

GetWhen has a few built-in functions (possibly more in the future). Functions can not be created within a GetWhen program.

Like all values, I/O is also only integers.

input()                                  //Gets one integer from input
output(x)                                //Sends x to output
when(<conditions>)                       //Returns a superposition/list (multiple values at once, see Neg) of all line numbers (of all lines in the program with higher or same priority) that, after execution, would result in all of the conditions (separated by ,s) being true.

Note: If there are no more integers to input, the input() function will return undefined. However, one does not have to output undefined after all outputs.

Variables can have the same names as the built-in functions.

when shenanigans

Using the when function outside of a line number will probably cause the program to become uncomputable and require the halting problem to be solved for the program to execute it. However, this is still valid syntax.

If a line that has priority would cause a when condition of a line with less priority to become false, that line is not executed. The same goes for one that would make a condition true.

Note: If a line at highest priority would not change its when condition, it will execute infinitely many times, without other lines having the chance to stop it.

If a variable would be changed inside of a when call, it is not changed outside of that call. This also applies to the input function (it will not move to the next input when used in a when call).


Although superpositions can exist in GetWhen, there is no syntax for creating one directly. They must be obtained through other means.

Computational class

GetWhen is probably Turing complete (or super Turing complete) via translation to a Minsky Machine using two or more unbounded variables. This has not been done yet because of laziness.

Example programs

  • Truth Machine:
when(!input()): output(0), ip=%          //If 0, output 0 and terminate
when(input()): output(1)                 //If 1, output 1 forever

Note: Any integer can be treated as a boolean or condition.

  • Cat
when(input()==%): ip=%                   //If no input, halt
when(input()!=%): output(input())        //Output the input, unless it doesn't exist
  • Fibonacci Sequence (forever)
1: x=1, y=1, z=0                         //Init
when(x!=%): output(x), z=x, x=x+y, y=z   //Fibonacci stuff
  • Grandfather Paradox
1: x=when(x==%), output(x), ip=%         //While executing the when call, as long as x would be undefined in a future line, there is no contradiction. However, since that never happens, the when condition would return undefined. Since x would be undefined at the end of line 1, the call would have to return 1, then undefined, then 1, etc.

It is currently unknown what is output when this program is run. Maybe x should be set to a superposition of 1 and undefined?