bell is a 2d string rewriting programming language. bell programs are made of an initial state and a list of rewriting rules to be applied on the given state. an editor for bell is still in the works, for now we can edit bell programs using plain text files.
There are two types of rewriting rules in bell.
unconditional rewrite rules:
X Y
this will simply replace all occurrences of the pattern 'X' with the pattern 'Y'.
conditional rewrite rules:
Z X Y
this rule will first check if the pattern 'Z' exists anywhere within our program state. if it does, it will do an uncondtional rewrite of pattern 'X' with pattern 'Y', else it will just skip to the next rule in the program.
patterns can be two dimentional
XX YY XX YY
here we defined an unconditional rewrite rule of two 2x2 patterns.
a simple bell program:
X2Y 1 # XXX XXX XXX #replace X with Y X Y
this program simply replaces all occurrences of the letter 'X' with 'Y'.
the first three lines are:
then we have the inital state of the program, in this case a 3x3 grid of the letter 'X'. after that we have our single rewriting rule which as explained by the comment replaces 'X' with 'Y'.
running this program should result in 3x3 grid of the letter 'Y'.
here is another slightly more complicated program:
ZIGZAG 3 # ------------------ |****>***********| |*****>**********| |******>*********| |*******>********| |********>*******| |*********>******| |**********>*****| |***********>****| |************>***| |*************>**| |**************>*| ------------------ >| <| |< |> >* *> *< <*
running this should result in bunch of "particles" bouncing between the walls in a "zigzag" pattern.
modifiers are a way to alter how rewriting rules behave.
in order to modify a rule you need to add a comment above the rule followed by the signature of the modifier. currently, bell supports only one, the random modifier (signature: '?'). a rule with the random modifier will choose a single random match and replace it.
a program to randomly fill the screen:
RANDOM 10 # ........... ........... ........... ........... ........... ........... ........... ........... #? . *
bell has a designiated character to handle keyboard input: '~'. the latest key pressed will always apear to the right of it.
a simple program demonstrating the use of '~':
MOVEMENT 15 # ~.......... ........... *********** ....@@..... ....@@..... ........... ........... ........... ........... ........... #if 'a' is pressed move left ~a .@@ @@. .. .@@ @@. #if 'd' is pressed move right ~d @@. .@@ .. @@. .@@ #if 'w' is pressed move up ~w .. @@ .. @@ @@ .. @@ .. #if 's' is pressed move down ~s @@ .. .. @@ @@ .. .. @@