Javagrid

Javagrid is a two dimensional language about programming in a grid.

Language overview
Code is written in cells. A cell consists of parameters and a number of directions with possible conditions. Parameters are optional, but the cell needs at least one direction or be completely empty.

Parameters are immutable within a cell. Each cell calls the next cell by calling one of the 4 directions: up, right, down, left.

The cells form a grid. When traversing in a directions, empty cells will be skipped over and when the execution cursor exits the grid it will enter again at the opposite site. The entry point and initial parameters are passed to the program at execution time.

The language currently supports 3 datatypes: number, string and cube. For numbers the usual math operators are allowed: "+ - / * %". Strings can be concatenated with the operator ".".

A cube is a datastructure with 6 sides that can work as a stack and as a queue that has a generic type indicating which of the other 2 datatypes it hold. Each movement on the grid in a certain direction also flips the cube in that direction. A cube is declared in the parameters like this:

foo: cube

In a grid cell a single value can be retrieved from the cube with the -> operator:

foo: cube -> bar

Values can be inserted into the cube when going in a direction with the <- operator:

left(foo <- "Value")

When entering and retrieving values from the cube the side of the cube that currently on the bottom is important. Values that have been inserted can either be retrieved from the same side (works like pop on a stack) or on the other side (works like dequeue on a queue). For example, if the cube is flipped right 1 time, the inserted elements cannot be retried. If the cube is flipped right again, the elements can be dequeued. If the cube is flipped right 2 more times, the elements can be popped.

Examples
Fizzbuzz:

Start at 1,1 with parameters 1,100

|i:number,j:number| |print(i)        | |down(i+1,j)     | |                |                                   |                 |                                   |                 |                  -@-@- i:number,j:number|i:number,j:number|i:number,j:number print("Fizz")   |i>j end        |print("FizzBuzz") right(i+1,j)    |i%15=0 right(i,j)|left(i+1,j) |i%5=0 down(i,j) | |i%3=0 left(i,j) | |up(i,j)         | -@-@-                 |i:number,j:number| |print("Buzz")   | |up(i+1,j)       | |                |                                   |                 |                                   |                 |

99 bottles

Start at 0,0 with parameters 1,98 and a cube.

i:number,j:number,q:Cube         |i:number,j:number,q:Cube          |i:number print("Take one down and pass ".                                            |i>0 left(i,j,q <- "".i)                   |"it around, no more bottles of beer on ".  i < j right(i+1,j,q)                      |                                          |"the wall."                             ." print(j+1." bottles of beer on the wall". |                                         |"                                       ." ", ".(j+1). " bottles of beer."         ."|                                          |No more bottles of beer on the wall, no". ")                                        |                                          |" more bottles of beer."                ." i=j down(q,j)                             |                                          |Go to the store and buy some more, ".i+1.                                            |                                          |" bottles of beer on the wall.") |                                         |                                                                                     |                                          |end --@--@-- q:Cube ,j:number                  |q:Cube -> s,j:number              |i:number right(q,j)                               |s ? print("Take one down and pass it"    |print("Take one down and pass it around, " |." around, ".s." bottles of beer on the ".|."1 bottle of beer on the wall." ."                                          |"wall."                                 ."|"                                       ." |"                                      ."|"                                                                                    |".s." bottles of beer on the ". |                                                                                    |"wall, ".s." bottles of beer." ."|."1 bottle of beer on the wall, 1 ".                                                |")                                        |"bottle of beer."                       ."                                           |s ? left(q,j)                             |") |right(j)                                 |up(i)

External resources

 * Repository in which the language is being developed
 * Demo page