In 1979, the Forth Interest Group (FIG) was formed to promote the use of the language and it has since then been the strictest enforcer of proper Forth implementations on home micros. Forth aficionados tend to look for the FIG seal of approval before using an implementation of the language. This standard is known as FIG-Forth and is embodied by the FIG-Forth installation manual as written by William Ragsdale.
FORTH STACK
1024 CONSTANT 1K (n . . .)
VARIABLE TOTAL in Poly-Forth
or 0 VARIABLE TOTAL in Fig-Forth
TOTAL ( . . addr)
Data retrieval is performed using the word (fetch)
TOTAL A ( . . . n)
while storing data uses! (store)
5 TOTAL !.)
TOTAL DUP A 3 + SWAP!
but using +! it becomes:
3 TOTAL +!
-1 TOTAL +!
CONDITIONS
(Char. . : NUM? 48 57 WITHIN ; true if ASCII numeral
AGE @ 18 IF 1 TOTAL + ! THEN
IF 1 MEN +!
ELSE 1 WOMEN +!
THEN
IF 1 MEN+1!
ELSE 1 WOMEN +!
THEN
THEN
(hi,n,n,lo. .hi,n,f)
(hi,n,f. .f,n,hi)
(f,n,hi. .f,f)
(f,f. .f)
(f. .f)
or exclusive of limits
: BETWEEN
(hi,n,n,6. .hi,n f)
(f,n,hi,. .f,f)
(f,f. .f)
<
SWAP ROT
>
OR
NOT;
ROT DUP ROT
SWAP ROT
AND;
true if n < the low limit
true if n > the high limit
true if n outside range
reverse condition
true if n > the low limit
true if n > high limit
true if both flags true
HERE PAD 10 CMOVE
CREATE STORE 20 ALLOT
STORE 20 EXPECT
STORE 20 TYPE
:VARIABLE CREATE 2 ALLOT;defines
VARIABLE
VARIABLE COUNTER defines COUNTER
0 COUNTER ! initialize to zero
:BYTES CREATE ALLOT ; (define bytes)
20 BYTES STORE (define store)
STORE 20 ERASE (initialize store)
=
(n, n _ _ f)
<
(nf, n2 _ _ f)
>
(n1, n2 _ _ f)
0=
(n _ _ f)
0<
(n _ _ f)
0>
(n _ _ f)
OR
(f, f _ _ f)
AND
(f, f _ _ f)
NOT
(f _ _ f)
XOR
(f, f _ _ f)
ERASE expects a start address and byte count on the stack and clears the appropriate memory area to zero.
functions. Consider a would-be definition for CONSTANT:
:CONSTANT CREATE , DOES> 2 ;
The box labelled 'Forth Logical Operators' shows the logical operators that can be used to act on information stored in the stack, while 'Forth Comparisons' shows how various words in the Forth vocabulary compare bits of information on the stack and how they relate their findings about those bits of information.
by a semi-colon.
(n,base . . base, n) bring the index to the
SWAP top of the stack
(base,n . . base, compute the byte
offset) 2 offset from the base
(base,offset . . ele- compute the address
ment addr) + of the element
used as 4 VALUE to return the address of the fifth element in VALUE (note that 0 would return the first element) so that the phrase :
4 VALUE A TOTAL +!
would add it into TOTAL.
Contributors: Dick Olney and Niklos Shawl Editor: Geof Wheelwright
Design: Nigel Wingrove Illustrations: John Hallett
The Jupiter Ace (pictured above) is the cheapest home micro to run the Forth programming language built into it. Many other home micros, including the Sinclair ZX81, ZX Spectrum and BBC micro, will run the Forth language in cassette form.
Forth was developed by Charles H. Moore in the late 1960s as a tool to increase his productivity. In 1971, he used the language to write a data acquisition program for the National Radio Observatory at Kitt Peak, Arizona.