lucky, the simplest computer language:
The basic construct of the language is the recipe.
{ A B C } leaves a thing that when RUN performs A B C in sequence.
Such a recipe can be given a name by :
{ A B C } : MYRECIPE
MYRECIPE becomes a new command that runs the recipe and
can be used in new recipe's.
{ A B } : C { C D C } : Q
We say that it is a new definition that is added to the glossary.
Note that a recipe can leave things that are used by other ones.
Constituents like C are just recipes themselves.
C can pass something to D. This is different from the
environment that is always implied in this discussion.
C can also detonate an explosive and destroy the computer,
as well as the operator.
'MYRECIPE gets the recipe itself back.
{ 7 } : LUCKY
is the way to define constants.
By adding a | , recipes are changed to run directly.
The closing } does not leave a recipe,
but rather the things that result from performing the instructions.
| checks a thing and considers zero as false, everything else as true.
{| A | B |} performs A , then if | finds false it terminates,
otherwise it does B and starts over again at A.
|{ A }|{ B }| | checks a thing, if it finds true it performs A else B.
|{ A }|{ }| can be abbreviated to |{ A }|
\ lucky considers a thing as a code that it passes to the next
recipe, leaving the interpretation to that recipe.
lucky has build in actions on one or two things that interpret
their input as either a signed number or a bitmask.
A logic result is a bitmask with all zeroes or all ones.
A number can identify a byte in computer memory,
then it is called an address.
"diadic operators" they have a pair of inputs
input output
+ - * / signed number pair arithmetic result
< <= > >= signed number pair logic result
OR AND XOR bitmask pair bitmask
The following actions work on a single thing.
"monadic operators":
Signed number:
NEGATE signed number arithmetic result
<< >> bitmask bitmask
INVERT bitmask/logic bitmask/logic
= <> whatever pair logic result
Comparing, subtracting of addresses are meaningful; negative
addresses are not allowed.
The next level, the word META and nested compilation.
{ A } { B } META DEFINER
DEFINER X adds a word X to the glossary. It remembers the
position of HERE and then performs A. Then if later X is
to run, it finds that position of HERE and performs B.
A predefined META word is DATA
{ } { } META DATA
Building a recipe between { and } is called compilation.
A compilation can be interrupted by a matched pair [ ].
Any code can be run between the square brackets, in particular
adding definitions to the glossary. However those definitions
can onley be used before the } of the enclosing recipe.
A [ ] pair shall leave nor consume things.
Loops, the word DO.
7 { A B C } DO performs the recipe 7 times.
IX will give the loop counter, starting from 0.
Expressions like 1234 leave a thing that is a signed number.
Expressions like "1234" leaves two things an address and a count.
Notes for the Forthers
Notably missing: AGAIN UNTIL AHEAD CREATE DOES> :NONAME
[:
<< >> are contrary to 2* 2/ a logical shift.
No double precision shit, not local shit.
Other Forth lectures
Go to the home page of Albert van der Horst