What!?

From Esolang
Jump to navigation Jump to search

What!? is a Turing-complete[1] language created by User:12mrsaturns.

What!? is tape-based and uses an integer tape like that of a Turing machine.[2]
It also, however, uses a second string tape (explained below).

The Tape(s)

What!? is different to most tape-based languages in the sense that it has two tapes.

The first tape is an integer tape.
All this means is that the only acceptable values (and in fact the only possible values) for this tape are integers.
Possible values include (but are not limited to) 124, 56, etc.
All values in this tape are initialised to 0.

The second tape is a string tape.
This tape holds strings such as This is a string, stringstringstring, etc.
It behaves like a normal tape in the sense that it only holds one string per tape "slot".
All values in this tape are initialised to "" (minus the quotes).

In order to keep track of which slot (or more commonly "location") the tape is at, a pointer is used.
Only a single pointer is used; it represents the current integer tape location and the current string tape location.
In the rest of the article,

  • "current integer value" will be used to refer to the value pointed to (by the pointer) on the integer tape.
  • "current string value" will be used to refer to the value pointed to (by the pointer) on the string tape.

Both tapes are limited to 256 memory spaces.
The only limitations are that integers are unsigned and limited to being 16-bits long and strings are limited to 256 characters.
This unfortunately does place some limitations on what input and output can be, however

Syntax

Syntax? What(!?) syntax?
You can try as hard as you can to make the code neat (or even ugly) but, no matter what, it'll still look like someone was randomly pounding on the keyboard whilst having a seizure.

Literal Forms

"string literal" - appends the given string literal to the current string value.
For example, the code "I like"" strings" would set the string value to I like strings if the current string value was previously empty.

numeric literal - replaces the current integer value with the given numeric literal.
For example, the code 12 13 (whitespace necessary) would set the integer value to 13 since the current integer value is overridden.

Operators[3]

There are two kinds of operators: tape operators and mathematical operators.

Tape Operators


! - outputs current integer pointer value as an ASCII character.
!! - outputs current integer pointer value as a decimal integer.
!!! - outputs current string pointer value.
!!!! - outputs a newline.
? - takes a character of input replaces the current integer value with its ASCII value.
?? - takes input as a decimal integer and replaces the current integer value with it.
??? - takes input as a string (newline delimited) and appends it to the current string value.
, - moves pointer location left by one.
. - moves pointer location right by one.
'anything' - subtracts n from the current integer value, where n is the length of the string enclosed between the single quotes.
( - marks the beginning of the loop.
) - marks the end of the loop.
[ - marks the beginning of a conditional.
] - marks the end of a conditional.

Mathematical Operators


All mathematical operators work similarly so there is no point in describing them (in detail) individually.
Simply put, a mathematical operator in What!? acts a lot like binary mathematical operators[4] in common higher-level languages. x sets the current integer value to current integer value x previous integer value.
Therefore

Operator Description
+ Adds current integer value to previous integer value
- Subtracts previous integer value from current integer value
* Multiplies current integer value by previous integer value
/ Divides current integer value by previous integer value

The above operators (plus the two literal forms) are the only valid What!? operators.
Anything else is a no-op.[5]
Please see Loops and Conditionals for further information on What!? loops and conditionals, respectively.

Golfing and Whitespace

Whitespace between operators is always optional unless it creates ambiguity.

When using the exclamation or question operators, they can be grouped.
However, they are read such that the biggest possible operator is always read before parsing the rest of the group.
This means that something like ??? ?? could be shortened to ????? and something like !!!! !!! could be shortened to !!!!!!!.
However, ?? ??? could not, as ????? is always parsed as ??? ??.

This means that whitespace between number literals is necessary as the biggest literal will always be grabbed.
12345 54321 cannot be compressed to 1234554321.

Loops

Loops work by running the code inside them until the current integer value is equal to 0.
The looped code will always run once. However, loops that only run at all if the current integer value is not 0 are also possible (by using conditionals). The loop condition is always checked at the loop ending marker.
If the current integer value at that point is equal to zero, the code continues execution.
Else, the loop is run again.

This means that the shortest hanging What!? program is

1()

1 makes the current integer value equal to 1 and () simply defines an empty loop.
Since the current integer value is never changed in the loop, it remains at 1 and the loop runs forever.

Conditionals

Conditionals work by comparing the current integer/string value to a given integer/string value.
Whether it's an integer or a string comparison is decided by the type of the given value.
The syntax is as follows: [literal form x code to be run if true], when x is a comparison operator (whitespace added for clarity).
This general form might be a bit confusing but it's simply due to how general it is.

Examples:

  • Integer - [1:!!]
  • String - ["A":!!!]

There are 4 comparison operators which can all be combined

Operator Description
: Checks if the given literal is equal to the current value.
; Checks if the given literal is not equal to the current value.
Also acts as a negation operator for other operators.
> Checks if the given literal is greater than the current value.
< Checks if the given literal is smaller than the current value.

Example combinations:
>: - greater than or equal to
<; - not smaller than
:; - not equal to (equivalent to ;)
<> - smaller than or greater than (equivalent to ;)

Conditionals can have unmatched opening or closing markers in them (e.g.: [0:(] or [0:)]).
However, these only really work with loop markers since markers are read from left to right individually.
This means that:

  • [0:[] would be read as [0: []
  • [0:]] would be read as [0:] ]

Both giving an unintended result.

Examples

99 Bottles of Beer

99 " bottles of beer on the wall, ".
" bottles of beer.\n".
"Take one down and pass it around, ".
" bottles of beer on the wall.".
,,,,'s'
(!! !!! !! . !!! . !!! ,, 's'[0:......"no more"!!!,,,,,,][0;!!] ...!!!,,, !!!!)
...."No more bottles of beer on the wall, no more bottles of beer."!!!. !!!!
"Go to the store and buy some more, 99 bottles of beer on the wall."!!! !!!!

Hello World

"Hello, World!"!!! !!!!

Cat Program

???!!!

Truth Machine

.??([1:!!][1;,1.(-)]),0!!

Additional Reading

  1. Visit Esolang's article or Wikipedia's article for more information on Turing-completeness.
  2. Visit Esolang's article or Wikipedia's article for more information on Turing machines.
  3. Visit Wikipedia's article for more information on operators.
  4. Visit Wikipedia's article for more information on binary operations.
  5. Visit Wikipedia's article for more information on no-ops.