While(true)

From Esolang
Jump to navigation Jump to search
The title of this article is incorrect because of technical limitations. The correct title is While(true){.

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 is false for the singular global variable, which can be read and written at any point
  • Empty input gets replaced by integer 0 since empty is not a valid value
  • Defining functions modifies the input program to not include the lines defining the function, thus breaking LOOK (might be fixed soon)
  • LOOK cannot be used to get values from before a definition and from within functions (it will probably error if you try)
  • Calling a function within another function will cause the 1st to stop, it will not continue after finishing the other (might get changed)
  • Maximum length of functions is 2147483646 (2^31-2) commands if you want to call functions within other functions, otherwise unlimited
  • When commands are used as arguments, they evaluate to 0 if they fail, and to whatever they are supposed to be otherwise (usually 1)
  • Fails: functions failing to execute, value 0, empty input, math falsiness, call doing nothing, define skipping
  • Currently a bug exists in the official extended interpreter which destroys all (A,B,...,Z) variables after each CALL.

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, copy 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)
look - take line above as input, look at the line VALUE lines above itself (only positive integers), copy it as its own value
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.

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 [] - globalr that can read named global variables
globalw [] - globalw that can make named global variables

Manual

How to end a program?

value 0
jump

How to define a function?

value name
define
#--- Function body
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 1
value 2
math A+B
define # will make a function named '3'
input
define # will make a function named the same as your input

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
defined
value hi
call # will call successfully

Why CALL?

You can calculate a result and do something based on that result, for example:

value 3
define
defined
value 1
value 2
math A+B
call # will call the function defined above

Why LOOK?

There are no named variables in this language (except GLOBAL), this 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 else entirely
value 12
look # this looks past the 10 lines of other code that we wrote (+ the value where to look, + itself)
value 2
math A+B # this will use the result of the previous calculation as B despite not being directly under it

This does essentially the same thing as MATH (by accident), so the method below might get removed soon, 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 else entirely
math K # will look 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) # if A=0, then output 5, if A!=0, then output -1
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 doesn't prove Turing-completeness):

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) # if B!=1, then output -1, if B=1, then output -3
jump
value step
call
globalr
math (A!=1) * 4 + (A==1) * (-1) # if A!=1, then output 4, if A=1, then output -1
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

Regularly they ignore anything that comes after them, in the extended version however, they make/access global variable of that name.

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 # does the same thing 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 # make a function called 'hello'
globalr A # access global variable A
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
print # will print 0 because global variable A does not exist
value 0
jump

Notice that global variable A was never explicitly created, and variables created by CALL only exist within the function.

External resources