Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.forth    |    Forth programmers eat a lot of Bratwurst    |    117,927 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 117,353 of 117,927    |
|    albert@spenarnc.xs4all.nl to All    |
|    What is Forth?    |
|    30 Jun 25 13:56:10    |
      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: you cannot sedate... all the things you hate (1:229/2)    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca