While(true)

Category:2021
Category:Languages
Category:High-level
Category:Implemented
Category:Cell-based
Category:Linear bounded automata
==Description==
While(true){ is an esolang written by User:Aonodensetsu over the weekend of 22-23.05.2021 after finding the Truttle1 YouTube channel prior to that.
It is a first try at making an esolang and is supposed to be Turing-complete while disallowing major use of variables and complex looping.
==Quirks==
* The program will repeat itself from the beginning after the last instruction unless explicitly halted
* All variables are integers if possible, strings otherwise
* All variables are anonymous, to access them they need to be directly above a command
* The above restriction is false for the singular global variable, which can be read and written at any point, as well as the extended feature set
* Empty input gets replaced by integer 0 since empty is not a valid value
* Commands can have different values in different contexts (accessing commands inside a DEFINE block will show their value as 0 because they exist in a separate context)
* When commands are used as arguments, they evaluate to 0 or whatever they are supposed to be (usually a math result)
==Commands==
call - look at the result of the line above and execute a function of that name, do nothing if that function doesn't exist
define - make a function that can be called by name, the value above define is the function's name (cannot be overwritten)
globalw - write the value of the line above to the global variable
globalr - read the value of the global variable, default 0, store it as its own value
input - ask user for keyboard input
jump - take the content of the line above and jump that many lines back (negative values jump forward, zero halts)
math [] - do an operation (+, -, *, /, %, ==, !=, >=, <=, >, <), variables taken from lines above, in the order they are encountered within the expression, called to as letters A-Z, comparison operations return 1/0
print - print the value of the line above as output
value [] - an anonymous variable
==Extended commands==
These commands constitute additional functions, that are not part of the language itself. They extend the language to allow for Turing-completeness.
define - can be overwritten
call [] - allows to pass variables to the function as in math (A,B,C...), all commands inside functions that take input will try to use these variables
globalr [] - can read named variables
globalw [] - can make named variables
==Manual==
===Shortest (infinite) loop===
 value hi
 print
===How to end a program?===
 value 0
 jump
===How to define a function?===
 value name
 define
 #--- Function body (non-empty)
 defined
===MATH variable input order explanation===
 value 1 # in this context, C
 value 2 # in this context, B
 value 3 # in this context, A
 math A+B+C # the order doesn't matter but A is always one line above MATH, B - 2 lines, etc.
 print
===Naming of functions===
 value hi how are you
 define # will make a function named 'hi how are you'
 value hi how are you
 defined
 value 1
 value 2
 math A+B
 define # will make a function named '3'
 value 3
 defined
 input
 define # will make a function named the same as your input
 value whatever you want
 defined
===Undefined functions===
Functions only exist after the point where they are defined, if they are called prior to that point, nothing happens, for example:
 value hi
 call # nothing happens
 value hi
 define # we define that function here
 value hi
 print
 defined
 value hi
 call # will call successfully
Will print hi only once, since before defining the function was not called
===Recursion===
While(true){ supports infinite recursion, for example:
 value f
 define
 value hi
 print
 value f
 call
 defined
 value f
 call
 value 0 # this will never be reached
 jump
Will print 'hi' forever.
Two functions calling each other indefinitely:
 value hi
 define
 value hi
 print
 value hello
 call
 defined
 value hello
 define
 value hello
 print
 value hi
 call
 defined
 value hi
 call
 value 0 # unreachable
 jump
Will print 'hi' and 'hello' alternating forever.
Notice that those programs will never end despite having the ending block (value 0; jump) in it.
===Why CALL?===
You can calculate a result and do something based on that result, for example:
 value 3
 define
 value hi
 defined
 value 1
 value 2
 math A+B
 call # will call the function defined above
===How to look at a previous result?===
There are no named variables in this language (except GLOBAL), MATH allows you to look at some value that was calculated previously that needs to be an input, for example:
 value 1
 value 2
 math A+B # we calculate a very important thing that we want to use later
 # --- 10 more lines of code that does something important
 math K # will look 11 (K - 11th letter) lines above
===Conditional jumps?===
Yes, but limited due to only one global variable, for example:
 value loop
 define
 value hi
 print
 globalr
 math A+1
 globalw # the 3 previous lines increment global variable by 1
 defined
 value loop
 call
 globalr
 math A>3 # returns 1 if global is more than 3, 0 otherwise
 math (A==0) * 5 + (A!=0) * (-1) # 5 if A=0, -1 otherwise
 jump # jumps back to the loop or does nothing
 value 0
 jump # halt
This will print hi four times.
===What can we do with this?===
Truth-machine, for example:
 value 1 # define function called 1
 define
 value 1
 print # print 1
 value 1
 call # go to itself
 defined
 input # read input
 call # go to function 1 if user input 1, nothing otherwise
 value 0
 print # print 0
 value 0
 jump # halt program
The Collatz conjecture (not generalized, so it doesn't prove Turing-completeness unfortunately):
 value step
 define
 globalr
 math A%2 * (3*A+1) + (A%2==0) * A/2 # if A%2 = 1, then output 3*A+1, if A%2 = 0, then output A/2
 globalw
 globalr
 print
 defined
 value enter an arbitrary integer
 print
 input
 globalw
 globalr
 print
 math (B!=1) * (-1) + (B==1) * (-3) # -1 if B!=1, -3 otherwise
 jump
 value step
 call
 globalr
 math (A!=1) * 4 + (A==1) * (-1) # 4 if A!=1, -1 otherwise
 jump
 value 0
 jump
==Extended manual==
This section of the manual covers commands that extend the language. Those commands can be used as regular, however they have additional features that enhance the functionality they provide.
===GLOBALW / GLOBALR===
You can now make named variables :)
 value hi
 globalw hello # store 'hi' into global variable 'hello'
 globalr hello # read the value of the global variable 'hello'
The 'regular' global variable has the name of _global
 globalr # read the regular global variable
 globalr _global # the same as above
===CALL===
Regularly, CALL just starts a function, now it can also give the function variables, for example:
 value hi
 globalw hello # store 'hi' into global 'hello'
 value hello
 define
 globalr A # access local variable A (given by CALL)
 print
 defined
 value hello
 call A # call function named 'hello' and store the line above (because A - 1st letter - the same logic as MATH) as variable A
 globalr A # will error because global variable A does not exist
 print
 value 0
 jump
Notice that global variable A was never explicitly created, and variables created by CALL only exist within the function.
Similar example, which shows the change of context:
 value hello
 define
 value hi
 globalw A # A in the function context, given to CALL as B
 globalr A
 print
 defined
 value hi
 value hello
 call B # B (2nd letter) is the first input, so within the function it will be A
 value 0
 jump
==External resources==
* Official interpreter