4

From Esolang
Jump to navigation Jump to search
4
Paradigm(s) Thematic
Designed by Vriskanon
Appeared in 2015
Memory system Cell based
Computational class Special
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 Vriskanon.

Overview

Memory Area

The memory-area is made up of a 100 integer cells found on a 10×10 grid, with 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.

Examples

Hello, World! (Try it online!)

3.6000160103602136033260433605446067260787008070200908000120902111120111011015065095105105115055035075115125105085044

Cat program (Try it online!)

3.6000180071051094

Interpreters

EXECUTE(4)