You are on the archived version of the www.TheForthSource.com website. These materials are presented for informational purposes only. We express our gratitude to 1PLs Co [urgent loans in the USA] for paying for hosting.


FORTH GUIDE

CHAPTER I

GETTING STARTED

The programming language, FORTH, harnesses the hardware to a simple group of functions. It is in a sense, the Assembler mnemonics for an ideal processor. The major use of a computer is for text or data input and output. The older machines were used for number crunching but today that use is limited on personal computers. A complete number package with floating point and transendental functions is a separate application available from Mountain View Press.

First you must have a running system with MVP-FORTH to load. Several object modules are distributed on this disk. (See the documentation file.)

If you have your printer connected and wish to log a hard copy of your session, enter a control-P. To stop the logging, enter another control-P. This DOS function is also implemented in MVP-FORTH. The FORTH function toggles a flag. When the flag is set, the screen is echoed on the printer. A hard copy is particularly useful when starting. You have a record of what you did when something unexpected happens. It can use alot of paper.

You cannot damage your hardware with FORTH. However, in moving rapidly and often without thinking, you can easily crash the system software. No problem! Just as when you stall your car, simply restart it. Often you will never know exactly what you did. Usually, a software restart of the system will be enough, but sometimes it may be necessary to turn the power off and on again. It is like car. You have to turn the ignition off then back on before you can rerun the starter.

For your feeling of security, you can leave FORTH any time.

        BYE   <cr>

Note that the command must be entered in upper case. MVP-FORTH is case sensitive. When entered in lower case you will be answered with the message: NOT RECOGNIZED. What is not recognized is indicated as part of the message. Try leaving FORTH. That wasn't so hard, was it?

When FORTH is first loaded, you will see on the display a header and a version number. Type a carriage return

       <cr>

The response on the screen will be "OK". The program is ready for you to enter any command you wish. The OK means that the system has finished what ever it previously was doing.

What functions can you use? There are about 140 common functions already defined and you can add to these as you wish by defining your own functions interactively.

Type a series of carriage returns and you will see a column of OKs down the side of the screen. Yes, go on and try it. This is intended to be interactive. Finally, you are at the bottom of the screen and you may notice that the OKs scroll off the top.

After an OK, type:

        JUNK   <cr>

and the system responds:

        NOT RECOGNIZED

Obviously, the system did not understand you. JUNK has not been defined. You have done no damage to the system. It just cannot do anything.

Well, what can you do? You will have to learn the functions which are available. To start with you will have about 140 functions to learn. You have already learned one, BYE. Try some more.

        page   <cr>

The response again is:

        NOT RECOGNIZED

The problem is that by convention most FORTH words are in upper case. There is a long history to this. In olden times, most terminals could only produce upper case. For portability including old terminals, only upper case has been used. There is no reason that you cannot use lower case for your own definitions if you wish. But to get started, just set the capital lock key. Now try again.

        PAGE   <cr>

Note the screen is cleared and you will see the OK at the top left. It is not that difficult. If your system only produces a carriage return, check with your documentation to learn how to make it perform its correct function.

Next suppose that you want to move down the page 4 rows before entering anything:

       CR CR CR CR   <cr>

And the OK appears down 4 blank rows.

Every FORTH word must be separated by one or more spaces or a carriage return. The carriage return will also tell FORTH to interpret and execute all of the words entered up to that point.

Any other combination of characters and symbols may be used in making new words. Use a mnemonic group of characters when you later define your own functions. Sometimes a long English word will have the best mnemonic value. In this case we might use CRS as a mnemonic for plural carriage returns.

Thus it would be much easier to simply enter:

        4 CRS   <cr>

But this gives the message:

        NOT RECOGNIZED

Now try a big step. No apology is made for this jump ahead at this point. If you do not understand, all you need to do is copy the example. Understanding will come later.

Define a function CRS which will move the cursor down any given number of rows. This is a function which will repeat the single CR function a given number of times.

        :  CRS  0 DO CR LOOP ;   <cr>

Now try:

        4 CRS   <cr>

This time the program understood you. You have added a function to the system. You will note that the added function can be used immediately. There is no edit, compile, load and run. This truly is interactive programming.

What did you do to define the function CRS? You will see more details of the process later, but you have enough here to use. The type of function is called a 'colon' definition. The definition begins with a colon! It is an interactive compiler directive.

Next you entered your name for the new function. The name can be any string of up to 31 alphanumeric and symbol characters except a space and a carriage return. The only reason the name you choose has any mnemonic value is that you selected it. You could just as well have typed:

        :  !@#$%^&*  0 DO CR LOOP ;   <cr>

Try that and prove it to yourself. Then test it:

        4  !@#$%^&*   <cr>

Next in the colon definition you entered a zero, 0 . The value is the beginning range for the DO ... LOOP structure. The way you will use the function is to first enter the number of rows you wish to skip. The value you entered will be one more than the other end of the range. The range 0 through 3 has four values - the desired number.

Inside the DO ... LOOP structure place the already defined functions you wish. In this case you placed CR within the loop. You wanted the single function, CR, to be repeated.

Finally, end the colon definition with a semicolon. As soon as you type the carriage return, the new definition is ready for use.

Again, what happens if you make a mistake entering the definition? First of all no real damage is done. You will be given a short message along with the location of the error. The definition will not be added to the dictionary of the system.

You cannot use a DO ... LOOP structure outside of a colon definition. If you try, you will have the system mark the DO and give you the message COMPILE ONLY. Another carriage return will return the usual OK prompt.

Some times the system will appear to go to sleep. Without restarting your program, a simple sequence of carriage returns often will get you back to the OK prompt. Who knows where the system went?

There is one exception to this rule - the message: NOT UNIQUE. This is not really an error. It means that the name you chose had been previously used for something else.

All previous uses of the word will remain unchanged, but all subsequent uses will have the new function.

HELLO

Now try to clear the screen and display the message HELLO, in the middle of the monitor. This will introduce the function of SPACES which is similar your new CRS , but has already been defined.

        PAGE 12 CRS 37 SPACES  ." HELLO"  12 CRS   <cr>

You have just entered interactive instructions which will be interpreted and execute as soon as you enter the carriage return. You also used the ." ... " pair of instructions. Whatever appears between the ." and a terminating " will be printed on the terminal.

The steps of our interactive instructions are as follows: Clear the display and home the cursor, move down 12 rows and in 37 spaces, type HELLO, and move down 12 more rows to take the OK out of the way. Once you become familiar with FORTH, you will find that the instructions are just as clear in FORTH.

Finally, make a function which will execute these instructions with a single command. This is adding a new colon definition to your FORTH.

        :  HELLO  PAGE 12 CRS 37 SPACES
           ." HELLO" 12 CRS ;     <cr>  

You can break up your definition into a couple of lines if necessary. A carriage return inside a colon definition is just compiled not executed. Now test your new definition.

         HELLO   <cr>

With these new tools, you can place any message you wish anywhere on the screen. You could have used "Hello world". Make up your own exercises. Choose names which are meaningful to you. When you are all done, you will have added several words to the vocabulary of functions available in your implementation of FORTH.

Perhaps you do not remember all of the words which you have added. You can see the new words as well as all of the old ones with the command:

        VLIST   <cr>

Hit any key to stop the scrolling. Then hit any key again to continue scrolling. While the scrolling is stopped, you can hit any key twice in rapid succession to leave the scrolling. Several MVP-FORTH functions which scroll data on the screen operate in a similar manner. In faster machines the delay may be too short. You can learn to fix that later by refering to ALL ABOUT FORTH.

The display begins with the latest definition first. Perhaps you will have started a definition which did not get finished. Even though the function is not available because you perhaps made an error in defining it, you will see the word in the dictionary. This is a peculiarity of the system.

Eventually, you will want to learn the function of the words displayed with VLIST. But as you have seen, there are things you can do in FORTH with only a small selected portion of them. Also many of the words are system primitives which you will probably never need. MVP-FORTH is completely open and documented. You are free to change it any way you wish. First you really should learn what is included and always make back up copies. Please do not distribute your versions as MVP-FORTH.

As you add words you are gradually filling up the dictionary and the space available in memory. It is best to have only those words in the dictionary which you will have occasion to use in any given application. The implementation of MVP-FORTH includes a number of common functions and serves as a basis for developing your own system. You might want to eliminate some of the words. Perhaps you will have no use for the ASSEMBLER. You can make the choice better after you have had some experience.

For now, each time you start the program, you will have to enter your favorite definitions again. At least at this stage that is the case. There are some things you will learn to do later. You will be able to write functions and save the source for your later use in FORTH screens. You will be able to load these screen without retyping them. Still later, you will learn to save the current object code image as a new file as the new application. For the present you will have to start over each time which is no big deal especially if your remember: KEEP IT SIMPLE!

Next Previous Contents