Intro to PrimaryColorForth
The goal here is to simply reproduce all of the examples from chapter 1 of Starting Forth in ColorForth.
Washing Machine Example
washer wash spin rinse spin ;
In ColorForth red words signify the start of a new definition. So "washer" is the new procedure. The ";" represents the call return. The green words are procedures that have already been defined. Let's look at the definition of rinse.
rinse faucets open till-full faucets close ;
The definition includes "things" (faucets) and verbs (open and close). The word "till-full" represents a delay loop. After the faucets "open" the word waits "till-full" before they "close".
Note. Unlike traditional Forth words cannot be defined from the command line. All words must be defined in the editor. Then the block containing the source text must be loaded. For example if you defined some new words in block 22 you would type:
Putting on a show
Forth was originally designed around a TTY display model. But ColorForth uses a GUI display, albeit one that is MUCH simpler than MS Windows, X-Windows or MacIntosh. So getting things displayed on the screen is a bit tricker than traditional Forth, but simpler than raw programming of most GUI operating system. The ColorForth word "show" creates a display task using the words following it.
Consider this definition.
ok show text 45 emit keyboard ;
This creates a new definition "ok" that draws a "*" at the top left corner of the screen. The word "text" moves the cursor to the top left of the screen and sets the drawing color to white. The word "emit" takes a number off the stack and draws the corresponding charecter. It's the same as "emit" in traditional Forth. Note that the charecter set is different from ASCII. The word "keyboard" redraws the keyboard and stack.
Chapter 1 of Starting Forth builds up an example on how to draw the letter "F" as a large charecter using "ASCII art". Here is a walkthrough of that example using colorForth.
The first word "space" draws a blank space on the screen.
space 0 emit ;
The next word "spaces" draws a certain number of spaces. For instance "5 spaces" would draw 5 spaces. Note that the "for..next" loop will be covered in detail later.
spaces for space next ;
The word "star" is similar to "space" but draws a star.
star 45 emit ;
The word "stars is similar to "spaces" but draws a number of stars.
stars for star next ;
The next words define the "F" using combinations of the above defined words. Note that "cr" stands for "carriage return". That simply moves the cursor to the next line.
side star spaces star ;
margin cr 30 spaces ;
blip margin star ;
bar margin 5 stars ;
f bar blip bar blip blip cr ;
ok show text f keyboard ;
After loading the block containing these words and typing "ok" from the command line a large "F" will be displayed on the screen.