4E4th-IDE - the Integrated Development Environment for your MSP430 LaunchPad ... Program Examples
There are numerous programming examples available on the net.
Today we start with the meanwhile famous "Stars" program from Leo Brodie's book "Starting Forth":
: STAR 42 EMIT ;
: STARS 0 DO STAR LOOP ;
: MARGIN CR 5 SPACES ;
: BAR MARGIN 5 STARS ;
: BLIP MARGIN STAR ;
: F BAR BLIP BAR BLIP BLIP CR ;
This is a classical Forth program to show how Forth works.
Forth uses factoring of problems into small programs, called WORDS.
Each new word is announced by the colon : and is called a colon-definition.
The word after the colon is the name of the program, and this name is followed by a number of other words, which are programs also.
A semicolon ; ends the definition of the word.
The above program is easy to read and easy to analyze:
42 is the decimal ASCII code of a typed star, and the word STAR emits this ASCII code, generating a star on the terminal screen.
The word STARS needs a number, it starts with 0 and sends as many STARs as this number says - inside a loop.
MARGIN creates a new line with CR (carriage return) and adds 5 SPACES as margin.
BAR paints a line consisting of 5 STARS.
BLIP creates only a BLIP - with a STAR, of course.
And finally the word F paints an F, using STARS with all of these words.
This picture looks new, and it is still new, after all these years.
More examples will be presented in time.