Container

From Esolang
Jump to navigation Jump to search

Container is an esoteric programming language created by User:Por gammer. The language models a finite set of nonnegative integers (denominated "containers") that evolve and effect each other through rules determined by the source code of a Container program.

Syntax

Valid Container expressions are composed of a head and a body, describing the behaviour of one container:

name[=value]:
x1 conditionA
x2 conditionB
x3 conditionC
...

In the 'head' of the expression, the container is named and (possibly) assigned an initial value, which must be a nonnegative integer. If none is given, it is set by default to zero. In the body of the expression a set of instructions defines the effect of other containers (called "contributions") on the current one. If the condition is met, its corresponding value is added to the container. Valid conditions are of the form:

ContA>=ContB
Container>=Constant
Container<=Constant

The IN, PRINT, OUT, EXIT and empty ("") containers are used for special purposes.

Execution

At each execution step, the value of every container is updated synchronously. So, for example, if we define A as:

A:
-10 B>=1
+3 W>=1

And the previous values for A,B,W were 2,0,1, we would know that the new value for A is 5. In case of a negative result, the container is set to zero. So if B=1 A would be 0, not -5. Contributions from the container itself and multiple contributions from the same container are allowed.

The PRINT container has the effect of printing the ASCII character corresponding to the last 7 bits of the OUT container every time it changes its value from zero to nonzero.

The program keeps a FIFO (read: First In First Out) queue of all the keys pressed by the user. Changing the value of the empty container from zero to nonzero has the effect of removing one item from the queue, and setting the IN container to its ASCII value (with EOF returning 0).

The EXIT container has the effect of closing the program if changed, with error code equal to its final value.

Examples

Hello, world!

Program by User:Bangyen:

A:
+1 EXIT>=1

PRINT:
+1 PRINT<=0
-1 PRINT>=1

OUT:
+72 A>=0
-115 A>=2
+93 A>=4
-100 A>=6
+103 A>=8
-173 A>=10
+114 A>=11
+0 A>=12
+99 A>=14
-194 A>=16
+205 A>=18
-214 A>=20
+106 A>=21
+0 A>=22
-59 A>=24

EXIT=1:
-1 A>=24

Implementations

A Python interpreter by User:Bangyen.