esolang

Javagrid

A program is a table of cells, and each cell calls a neighbour, carrying a cube that rolls on the way.

Turing complete: unknown · ●●○ moderate · esolangs.org

Tested with 2 known programs · Test method

Run it

Expected: 12Fizz4BuzzFizz78FizzBuzz11Fizz1314FizzBuzz

The idea

Javagrid draws a program as a grid. Every cell is a small function. It names its parameters, may print, and then calls the cell above, to the right, below or to the left with new values. Empty cells are passed over, and a call off one edge comes back in at the opposite edge. Where the program starts, and with which values, is given when it runs.

Read the story

Its one data structure is a cube with six faces. Each move rolls the cube over one edge in that direction. A value goes in on the face the cube stands on. It comes back out from the same face like a stack, from the opposite face like a queue, and not at all from the four faces in between.

The machine

A | parts the columns, and a line of - and @ ends a row of cells. A cell starts with its parameters and then holds statements, each an optional condition followed by one call.

PartDoes
i:number,j:numberThe cell's parameters; the types are number, string and cube
q:Cube<string> -> sTake a value out of the cube into s on the way in
i%3=0 left(i,j)If the condition holds, call the cell to the left with these values
s ? left(q,j)Call left if s is not empty
q <- "".iPut a value into the cube as it is passed on
print(...) end()Print; stop
+ - * / % . < > =Arithmetic, joining text, comparing

The first call whose condition holds is taken. A string may run on past the end of a line, and then it holds a line break there. The "Start at 1,1 with parameters 1,100" is the input, as --input '1,1 1,100'; a cube parameter starts empty.

Example

The FizzBuzz starts in the middle cell.

The FizzBuzz starts in the middle cell. It sends multiples of 15 right, of 5 down, of 3 left and the rest up, and each of those cells prints and sends the next number back. Print adds no line break, so the words and numbers run together. This example counts to 15 instead of 100.

The 99 bottles of beer uses the cube as a stack. The top left cell bounces between itself and its right neighbour, which puts each count into the cube. Then the bottom middle cell takes them out again, the last one first, and each time goes left and comes back so that the cube stands on the same face. The program starts with 1,98; with 1,3 it sings from 4 bottles.

Expected: 4 bottles of beer on the wall, 4 bottles of beer. Take one down and pass it around, 3 bottles of beer on the wall. 3 bottles of beer on the wall, 3 bottles of beer. Take one down and pass it around, 2 bottles of beer on the wall. 2 bottles of beer on the wall, 2 bottles of beer. Take one down and pass it around, 1 bottle of beer on the wall. 1 bottle of beer on the wall, 1 bottle of beer. Take one down and pass it around, no more bottles of beer on the wall. No more bottles of beer on the wall, no more bottles of beer. Go to the store and buy some more, 4 bottles of beer on the wall.

The song only comes out right one way. The value has to go in before the cube rolls, and the bottom middle cell then finds it on the face it went in by.

Patterns it teaches

Further

Two-dimensional languages

Write your own in Run Convert a program from Javagrid

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: javagrid.

Command line

shib run javagrid program.txt --input '1,1 1,100'

The program is long; save it as program.txt first.

shib manual javagrid

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/javagrid.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org