- This article contains unusual Unicode characters for a "graphical" language. If they don't show up as they should, you may have to install extra fonts to see them.
The purpose of Tubes is to have a cool looking source code.
The language has a memory infinite in all directions but with limited cell values. Cells can only have the values 0, 1, 2 or 3.
The code is a two-dimensional field of cells made up of the characters above.
Execution starts at the ▶ symbol. This symbol must not appear more than once in the code.
From the ▶ symbol the function pointer moves right.
If the function pointer enters a cell with an unknown character, the program will abort and print out the encountered character as its error message. (This can be useful for debugging code.)
Allowed characters are:
- All operators.
- Movers with a branch pointing in the direction the function pointer is coming from.
If the function pointer encounters an operator, it executes the operator and moves on straight.
If the function pointer encounters a mover, it moves along the path taking a branch depending on the value of the cell the memory pointer is pointing at.
The exit taken depends on the allowed branches, where the direction the function pointer is coming from is not allowed. The directions come with a priority order: right, down, left, and up.
To decide which branch is taken, the not allowed ones are removed, and the rest are listed in priority order. The first one has the value 0 and the following ones have the values 1 and 2 (there is a maximum of 3 different possible paths). The branch with the value (value of the memory cell % number of allowed branches) is taken.
If the branch from which the function pointer is leaving the cell is double lined then the memory pointer is moved one step in the corresponding direction.
Change memory to a value read from stdin. Just values of 0, 1, 2 and 3 are accepted, the rest are ignored. Depending on implementation one can use ascii art input, too. As an example, the following can be used:
0=: 1=[space] 2=█ 3=EOL
Print out a value from memory to stdout. Rules are the same as for read.
The function pointer starts here.
This causes the program to terminate without an error.
Add 1 to the value of the cell the memory pointer is pointing to, if the value isn't 3. If the value is 3 the value of the cell is changed to 0.
Example code snippets
Print 01230123 in a loop:
┌┐ ◉◆ ║║ ▶┤│ └┘
┌─▷exit if mem=2 ▶┼┬▷exit if mem=0 │└▷exit if mem=3 └─▷exit if mem=1
Tubes is Turing complete as one can rather easily simulate a Turing machine in it.
As an example here is Wolfram's 2,3 Turing machine implemented in Tubes:
┌◉◉◉─┬─┬┐ ├─╖┌─◉─◉◉┐ └┐└┼┐╙╕│╙╛ ▶┘ └◉─┘│ ┌───┘┌┬┘ ╘╖┌◉═╜│ ┌┘◉ ╙╕ │┌┼◉◉──┘ ├╜└◉═╖ └────┘
We are writing a C based interpreter at the moment. If it's done it will be uploaded somewhere.