• What is Forth?

    From albert@spenarnc.xs4all.nl@21:1/5 to All on Mon Jun 30 13:56:10 2025
    A Forth system is a database of small programs.
    The database is called the dictionary.
    The programs are called word's, or definitions.
    The explanation of words from the dictionary is called
    a glossary.

    First of all, a Forth system is an environment that you enter by
    running it:

    prompt> thisforth

    Like in a Disk Operating System a word is executed
    by typing its name, but unlike in a DOS several programs
    can be specified on the same line, interspersed with
    numbers. Also names can be anything, as long as they don't
    contain spaces.

    A program may leave one or more results,
    and the next program can use it.
    The latest result is used up first, hence the name lifo buffer.
    (last in, first out).

    For example:

    forth example:
    "
    1 2 + 7 *
    OK
    .
    21
    "
    1 2 and 7 are numbers and are just remembered as they are typed in.
    OK and 21 OK are the answer of the computer.
    `` + '' is a small program with an appropriate name.
    It adds the two numbers that were entered the latest, in this
    case 1 and 2. The result 3 remains, but 1 and 2 are consumed.
    Note that a name can be anything, as long as it doesn't contain
    spaces.
    The program `` * '' multiplies the 3 and the 7 and the result is 21.
    The program `` . '' prints this results. It could have
    been put on the same line equally easily.

    You will be curious about what are all those commands available.
    Of course they are documented, but you can find the exact set
    by typing WORDS .
    Programs can be added to the database by special programs: the so
    called defining word's.
    A defining word generally gets the name of the
    new word from the input line.

    For example: a constant is just a program that leaves always
    the same value.
    A constant is created in this way, by the defining word CONSTANT :

    127 CONSTANT MONKEY 12 .
    12 OK

    You can check that it has been added, by typing WORDS again.

    The above must not be read like:
    a number, two programs and again a number etc.... ,
    but as:
    a number, a program and a name that is consumed,
    and after that
    life goes on. The `` 12 . '' we put there for demonstration purposes,
    to show that CONSTANT reads ahead only one word.
    On this single line we do two things, defining MONKEY and printing the
    number 12.
    We see that CONSTANT like any other program consumes some
    data, in this case the 127 that serves as an initial value for
    the constant called MONKEY .

    A very important defining word is `` : '', with its closure
    `` ; ''.

    : TEST 1 2 + 7 * ; 21 .
    21 OK


    In this case not only the name `` TEST '' is consumed, but none
    of the remaining numbers and programs are executed, up till the
    semicolon `` ; ''.
    Instead they form a specification of what `` TEST}) must do.
    This state, where Forth is building up a definition, is called
    compilation mode .
    After the semicolon life continues as usual.
    Note that ` ; '' is a program in itself too.
    But it doesn't become part of TEST . Instead it is executed
    immediately.
    It does little more than turning off compilation mode.

    TEST TEST + .
    42 OK
    : TEST+1 TEST 1 + . ; TEST+1
    22 OK

    We see that TEST behaves as a shorthand for the line up till
    the semi colon, and that in its turn it can be used as a building
    block.

    The colon allows the Forth programmer to add new programs
    easily and test them easily, by typing them at the keyboard.
    It is considered bad style if a program is longer than
    a couple of lines.

    Because of the way Forth remembers numbers
    you can always interrupt your work and continue.
    For example
    : TEST-AGAIN
    1 2 + [ 3 4 * . ]
    12 OK
    7 * ;
    OK
    What happened here is that
    some one asked you to calculate ``3 times 4'' while you
    were busy with our test example. No sweat!
    You switch from compilation mode
    to normal (interpret) mode by `` [ '' , and back
    by `` ] ''.
    In the meantime, as long as you don't leave numbers behind,
    you can do anything.
    (This doesn't apply to adding definitions, as you are
    in the process of adding one already.)
    --
    The Chinese government is satisfied with its military superiority over USA.
    The next 5 year plan has as primary goal to advance life expectancy
    over 80 years, like Western Europe.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paul Rubin@21:1/5 to All on Mon Jun 30 14:08:03 2025
    This is a nice article, thanks for writing it.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From albert@spenarnc.xs4all.nl@21:1/5 to All on Tue Jul 1 23:28:11 2025
    lucky7 is a database of small programs.
    The database is called the dictionary.
    The programs are called word's, or definitions.
    The explanation of words from the dictionary is called
    a glossary.

    First of all, a lucky7 system is an environment that you enter by
    running it:

    prompt> lucky7

    Like in a Disk Operating System a word is executed
    by typing its name, but unlike in a DOS several programs
    can be specified on the same line, interspersed with
    numbers. Also names can be anything, as long as they don't
    contain spaces.

    A program may leave one or more results,
    and the next program can use it.
    The latest result is used up first, hence the name lifo buffer.
    (last in, first out).

    For example:

    lucky7 example:
    "
    1 2 + 7 *
    OK
    .
    21
    "
    1 2 and 7 are numbers and are just remembered as they are typed in.
    OK and 21 OK are the answer of the computer.
    `` + '' is a small program with an appropriate name.
    It adds the two numbers that were entered the latest, in this
    case 1 and 2. The result 3 remains, but 1 and 2 are consumed.
    Note that a name can be anything, as long as it doesn't contain
    spaces.
    The program `` * '' multiplies the 3 and the 7 and the result is 21.
    The program `` . '' prints this results. It could have
    been put on the same line equally easily.

    You will be curious about what are all those commands available.
    Of course they are documented, but you can find the exact set
    by typing "lsn" .
    Programs can be added to the database by special programs: the so
    called defining word's.
    A defining word generally gets the name of the
    new word from the input line.

    For example: a constant is just a program that leaves always
    the same value.
    A constant is created in this way, by the defining word CONSTANT :

    127 CONSTANT MONKEY 12 .
    12 OK

    You can check that it has been added, by typing lsn again.

    The above must not be read like:
    a number, two programs and again a number etc.... ,
    but as:
    a number, a program and a name that is consumed,
    and after that
    life goes on. The `` 12 . '' we put there for demonstration purposes,
    to show that CONSTANT reads ahead only one word.
    On this single line we do two things, defining MONKEY and printing the
    number 12.
    We see that CONSTANT like any other program consumes some
    data, in this case the 127 that serves as an initial value for
    the constant called MONKEY .
    You can combine programs with { and } like so:

    { 1 2 + 7 * } 17 .
    17 OK

    The commands between { and } are not executed directly, the sequence
    leaves a recipee.
    It can be RUN.

    RUN .
    21 OK

    You can give a recipee a name, analogous to CONSTANT
    { 1 2 + 7 * } : TEST
    OK

    Now you can use TEST like all other words in de the dictionary.

    TEST TEST + .
    42 OK
    : TEST+1 TEST 1 + . ; TEST+1
    22 OK

    We see that TEST can be used as a building block.

    The colon allows the lucky7 programmer to add new programs
    easily and test them easily, by typing them at the keyboard.
    It is considered bad style if a program is longer than
    a couple of lines.

    You can interrupt the creation of a recipee by [ ] to
    give direct commands.
    For example
    { TEST-AGAIN [ 12 CONSTANT twelve ]
    twelve twelve + 3 * }
    OK
    Here you add a constant to the dictionary, and use it.
    to normal (interpret) mode by `` [ '' , and back
    by `` ] ''.
    (There is a restriction, you cannot leave anything behind).

    Groetjes Albert

    P.S. Note that it is shorter and makes more sense than the definition
    of Forth.
    --
    The Chinese government is satisfied with its military superiority over USA.
    The next 5 year plan has as primary goal to advance life expectancy
    over 80 years, like Western Europe.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From albert@spenarnc.xs4all.nl@21:1/5 to albert@spenarnc.xs4all.nl on Wed Jul 2 14:01:12 2025
    In article <nnd$6da712e9$10ba1712@ac6bb1addf3a4136>,
    <albert@spenarnc.xs4all.nl> wrote:
    <SNIP>
    You can combine programs with { and } like so:

    { 1 2 + 7 * } 17 .
    17 OK

    The commands between { and } are not executed directly, the sequence
    leaves a recipee.
    It can be RUN.

    RUN .
    21 OK

    You can give a recipee a name, analogous to CONSTANT
    { 1 2 + 7 * } : TEST
    OK

    Now you can use TEST like all other words in de the dictionary.

    This must be
    TEST TEST + .
    42 OK
    { TEST 1 + . } RUN
    22 OK
    --
    The Chinese government is satisfied with its military superiority over USA.
    The next 5 year plan has as primary goal to advance life expectancy
    over 80 years, like Western Europe.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)