Variables and pseudo random numbers generators - makingthematrix/gailibrary GitHub Wiki
Ideally, GAI functions should only read data and compute one value, which is then stored until the end of the iteration. This is approach I would like to promote: it supports concurrent computation of cells, the functional programming paradigm, and helps avoid a whole range of errors. But sometimes it can be too restrictive.
Consider a pseudo-random numbers generator (PRNG), a special type of a variable. If the programmer uses only values and lazy vals, the order of calling functions is not important. But the number generated by PRNG differs with every call. So, if I want that two GAI iterations on the same data to give me the same results, I need to have the functions called in the sameorder . And PRNG is an important feature, it's good to have it, and to have it I have to basically have the functionality which works for other variables as well. Variables are not idiomatic (from the cellular automata point of view) and are error-prone, but they have at least one big advantage: they enable programmers to break big functions into smaller ones. Without variables each function has to work independent from one another – hence no need for ordering.
When the function calls Cell::set
the new value is stored in results
and all the updates are performed at the end of the iteration. If Cell::set_var
is called instead, the variable is set immediately and may be used by consecutive functions. But it also means that the function which sets the variable must be called before the one which uses it, so it is required to declare in the function’s registration what variables it requires, and what variables it sets (or modifies). This way GAI can figure out which functions have to be called one after another.
Just as in the case of lazy vals, initially the requirements for variables will be really just warnings: „please don’t do that, it’s not safe”. Later on I will try to introduce some sort of checks, enforcing the rules.
lazy vals <- | -> Cell types