Forthrooms
Forthrooms is a 3-command esolang by User:TBPO that has two-dimensional memory, despite having only one-dimensional program.
Setup
Forthrooms memory is an infinite doorspace, which is an infinite two-dimensional grid of rooms, each having an integer from 0 to the length of the program, separated by doors, each of them being open or closed; and a queue of natural numbers.
There are two pointers in Forthrooms:
- IP, which starts on the beggining of a one-dimensional program and aways goes right, occasionally jumping;
- Wanderer, which has a direction and initially points north. It starts in an empty doorspace, with all rooms initially set to 0 and all doors closed.
Every time IP moves naturally (jumps do not count), a cycle passes. It's basic unit of time in Forthrooms.
Instructions
< | Left | Move left. |
^ | Forth | If the door the Wanderer is pointing to is closed, open it. Else, go through it and close it. |
* | Mark | If the door the Wanderer is pointing to is open and the room behind it is non-zero, reset it and enqueue the value. Else, if the queue is non-empty, dequeue a number and set the current room to it. Else, set the current room to the number of current instruction, counting from 1. |
When Wanderer steps into a non-zero room, IP jumps to the instruction number the room's value, not executing it.
Memory-mapped I/O
- This section is still a work in progress. It may be changed in the future.
Techniques
Moving
Move through a closed door:
^^
Move through an open door without closing it:
^<<^<<
Conditional branch
^<
This statement checks if the door is open, then unconditionally switches it. If it's true, then Wanderer moves one door forward, then unconditionally moves left and executes the rest of the program on a set of data (doors) that depends on the result of the statement.
Examples
p12 loop
It's the smallest infinite loop in Forthrooms. It's 7 instructions long and repeats every 12 cycles.
*^^<<^^
p8 loop
It's the fastest infinite loop in Forthrooms. It's 9 instructions long and repeats every 8 cycles.
*^^<<^^<<
Spaceship
It's the smallest structure that moves infinitely. It doesn't leave any trail. It's 17 instructions long and moves one room every 16 cycles.
*^^<<^*<<*<<^<<^^
Puffer
It's the smallest structure tha grows without bond. It leaves a trail of open doors. It's 23 instructions long and moves one room every 22 cycles.
*<<^<<^^<<^*<<*<<^<<^^