Grid9 Documentation
Basic Description
To explain Grid9 in one sentence it is an esoteric interpreted language made in Nim based on a 3x3 grid of cells for a total of 9 cells in the grid where the values of the cells consist of zeros and ones.
You can interact with these cells by setting them (s) flipping them (f) or setting all the cells to a value (a). With all of these ways you can interact with the cells you may wonder what you can do with them and the answer to that is that every output able character in this language has its unique combination of cells. Now you may wonder why 9 cells why not 8 like the size of a byte. Well, the answer to that is well it is non, but some useful things you can do with that 9th cell use it for your variable storage so you can store a zero or one that may be used to sway logic.
This language doesn't stop at just being able to change a few numbers; there are statements, control of flow operators, and more.
Cell Modification
Set
The set command is used to set a cell to a value.
The syntax for this command is "s" followed by the cell id and then the value you want to set it to. This unlike the flip command sets the value for certain of a cell's value.
For example, if you wanted to set cell 0 to 1 you would run the code below.
s01
Flip
The flip command is used to flip a cell to a value.
The syntax for this command is "f" followed by the cell id that you would like to flip (0-8). This unlike the set command flips the value with the uncertainty of a cell's value.
For example, if you wanted to flip cell 2 you would run the code below.
f2
Set-all
The set-all command is used to set a cell to a value.
The syntax for this command is "s" followed by the cell id and then the value you want to set it to. This flips all cells with the certainty of a cell's value.
For example, if you wanted all the cells to have the value 1 you would run the code below.
a1
IO
The print command is used to print the grid glyph character to the console.
Now, this command needs a little explanation to understand it, but every output-able character has its combination on the grid and those are called "glyphs". The print command converts these "glyphs" into the single character that they represent. Also, the print command will print the current queue instead of the current glyph if the queue contains anything. The syntax for this command is "p".
For example, the character "a" is represented by 000000010. If you were to flip cell 7 (the cell ids start at 0) and then it would print "a" like in the code shown below.
f7 p
Queue
The queue command is used to print multiple "glyphs" or characters together.
The syntax for this command is "qs" to add a glyph to the queue and "qc" to completely clear the queue.
For example say you want to print two "r" letters next to each other. To do this you would want to make the glyph for "r" save it in the queue and then again save it and then print it to get the output "rr" like in the code shown below.
f4 f7 f8 qs a0 f4 f7 f8 qs p
Logic
If
The if command is used to check if a cell is a zero or a one.
The syntax for this command is "i" followed by the cell id and then a "=" or a "!" for a not equal to the value of the cell you are testing for. Remember to also close an if statement, to do this you have to use a "}"
For example, if you wanted to test cell 2 for zero and if true print the letter c you would run the code below.
i2=0 f6 p }
While
The while command is used to loop in your code as long as its conditions are met.
The syntax for this command is similar to the if command, the syntax for it is a "w" followed by the cell id and then a "=" or a "!" for a not equal then the value of the cell you are testing for. Remember to also close a while statement, to do this you have to use a "]"
For example, if you wanted to loop while cell 2 is zero that prints the letter c infinitely you would run the code below.
w2=0 f6 p ]
Exit
The exit command is used to exit the current while loop.
The syntax for this command is just "e".
For example, if you wanted to loop while cell 5 is a zero that prints the letter c but then breaks out of the loop you would run the code below.
w5=0 f6 p e ]
Grid
Give
The grid command is for users to give a glyph pattern as input to the script.
The syntax for this command is "gg".
For example, if you wanted to make a simple glyph-to-character converter you would that would do is it would take input and print out the character as output. The code for this is shown below.
gg p
Save and Load
The save and load commands are used to save and load glyph patterns to other grids that can be used for layer.
The syntax for this command is "gs" and then an id from 0-8 to save; and then "gl" and an id from 0-8 to load.
ar s00 p gs0 ar s00 p gl0 p
Mask
The mask command is used to mask a saved grid on top of the current grid.
The syntax for this command is "gm" and then an id from 0-8 to mask.
ar gs0 ar gm0
Xor
The xor command is used to xor the current grid or a saved grid.
The syntax for this command is "gx" and then an id from 0-8 or "c" if you wanted to do the current grid to xor.
f6 f2 f0 f7 gxc
Misc
Back
The back command is used to go back to previous instructions in the code.
The syntax for this command is "b" followed by the number of instructions you want to go back. Note this value can be any number higher than 0.
For example, if you wanted to go back 23 instructions you would run the code below.
b23
Delay
The delay command is used to wait in-between instructions inside of your code.
The syntax for this command is "d" followed by the number of seconds you want to wait before continuing. Note this value can be any number higher than 0.
For example, if you wanted to flip a value on the grid, then wait for 14 whole seconds, and then finally print it out you would run the code below.
f6 d14 p
Terminate
The terminate command is used to terminate the program.
The syntax for this command is just "t".
For example, if you wanted to terminate the program if a condition is met you would do it in the code below. As you can see the code "f7p" will never get run because by default all cells are 0 and that condition is true so it terminates the program.
i0=0 t } f7 p
Config
Toml
In Grid9 version 2022-020 and above you can now use toml files to configure the way code is run. This is a new feature and is still not perfect so it may not work as expected.
The structure for the config is shown below. If you do not define a config value that value will be set to its default value. While the rest are set to the values you defined.
[
config
]
advancedParse
=
true
dontCache
=
false
echoGridMod
=
false
noLog
=
false
verbosity
=
1
These config options are used to change the way Grid9 interacts with your code. For example, you can run advancedParse which will make the program start slower but can fix issues in your code. The options can also allow you to see more technical information about the program. For example, turning on echoGridMod will print you the grid after every instruction that modifies the cells in some way.
Tools
Converter
The converter is a tool that allows you to convert your scripts into a formats or text into Grid9.
The converter tool is an optional component that can be installed with Grid9. If you do not have it installed you have to re-run the installer and select the converter option. If you are on Linux you should have the binary already.