4
Paradigm(s) | Thematic |
---|---|
Designed by | User:Vriskanon |
Appeared in | 2015 |
Memory system | Cell based |
Computational class | Turing complete |
Major implementations | py-four, ruby |
File extension(s) | .4 |
4 (read four, /fɔː/), named after the last digit of pi (a joke from the webcomic Homestuck), is a thematic esoteric programming language with a small set of operations created by User:Vriskanon.
Overview
Memory Area
The memory-area is made up of a 100 integer cells, which can be thought as being on a 10×10
grid, with each having an initial value of 0
. Each is described by its coordinates:
00 01 02 .. 09 10 11 12 .. .. .. .. .. .. .. 90 91 92 .. 99
Program structure
All codes in 4 must start with 3.
and end with 4
. If they don't, it is considered a syntax error.
The body of the code contains a few operations, each made up of a single-digit operation name and [0 to 3] 2-digits operands (variables).
For example, a code that sets the cell 05
's value to 1
would look like this (the spacing is simply for aesthetics - it is poor form to have any non-number characters in one's code):
3. 6 05 01 4 prefix opcode operand operand suffix
The table below summarizes the operations:
Opcode | Operation | First operand | Second operand | Third operand | Description |
---|---|---|---|---|---|
0
|
Addition | Target cell | First cell | Second cell | The target cell is set to the value of the first cell added to the second cell. |
1
|
Subtraction | Target cell | First cell | Second cell | The target cell is set to the value of the first cell minus the second cell. |
2
|
Multiplication | Target cell | First cell | Second cell | The target cell is set to the value of the first cell multiplied by the second cell. |
3
|
Division | Target cell | First cell | Second cell | The target cell is set to the value of the first cell divided by the second cell (rounded down). |
4
|
Exit | Exits the code. | |||
5
|
Output | Target cell | Prints the Unicode character of the target grid cell. | ||
6
|
Set | Target cell | Two-digits number (00 -99 )
|
The value of the target grid cell will be set to the number. | |
7
|
Input | Target cell | Takes a single character input and sets the value of the target cell to its Unicode value. | ||
8
|
Begin loop | Target cell | If the value of the target grid cell is 0 , skips to the loop end (see next). Otherwise, keeps executing.
| ||
9
|
End loop | Jumps back to the beginning of the loop. |
Computational class
Assuming the cells store unbounded integers, 4 is Turing complete as Portable Minsky Machine Notation programs can be compiled into it. If the cells are bounded then 4 is in the class of bounded-storage machines.
The Try It Online interpreter supports unbounded integers, and is thus a Turing complete implementation.
Examples
Hello, World!
3.6000160103602136033260433605446067260787008070200908000120902111120111011015065095105105115055035075115125105085044
Cat program
3.70080050070094
Truth-machine
3.70050060148102000180250094
Print the pi character
This program uses 16×60 to make 960.
3.600166016020200015024
Interpreters
- A ruby interpreter which, for the sake of novelty, accepts the program source as a direct call on the number
4
. - A short python interpreter.
- py-four - A python 4 interpreter.
- A APLBAONWSJAS interpeter:
EXECUTE(4)