BFRTH8.DOC

(18 KB) Pobierz
*lm10:rm70
*hd3:,Start Blazin' Forth,page -#-
*ln2
*cn1;FORWARD*cn0
*ln2
     By far the most read (and best) instructional book on Forth is STARTING FORTH, by Leo Brodie. It is very clear, amusing, and covers the territory. Unfortunately, since Starting Forth was written, Forth itself has undergone considerable evolution, so not everything in Starting Forth is applicable today. Additionally, Starting Forth is based on a particular dialect of Forth (POLY-FORTH), which is a Forth implementation by Forth Inc., the company Mr. Brodie worked for when he wrote his excellent book. As a result, even for the time it was written, certain passages and examples would not work on anything but a Forth Inc. system. ( .S is a classic example of this, but there are others. )
     Blazin' Forth is written to support the Forth-83 standard. This is the most recent available standard, and the one which in my opinion, and from all I can tell, the opinion of most other Forth users, the most significant standard so far. As a result, it is not completely compatible with Starting Forth. ( Mr. Brodies latest book THINKING FORTH , uses Forth-83, by the way.)
     Perhaps surprisingly, most of the examples Brodie gives work without a single change in Blazin' Forth. This document is intended to help you when the examples don't work as described, speeding up the learning process, easing the pain, and generally helping to prevent you from damaging yourself or your computer through frustation. Differences between the earlier Forth's and the present standard are described, and alternate definitions are provided.
     Not all the comments are about differences - there are many more words in Blazin' Forth than are included in the Standard. I couldn't resist telling you about a few of them.
     Good luck! And may the Forth be with you.
*ln2
                         SDB
                         NY NY 1985
*fp0
*cn1;Chapter 1*cn0

Page 11

The definition STAR will work as supplied. Blazin' Forth contains a word called ASCII that can make words like STAR more readable (and save you a lot of time looking up characters in ASCII tables). Using ASCII , the definition of STAR would be:

   : STAR    ASCII *  EMIT ;

Try it - you'll like it.

By the way, if you change the definition of MARGIN on the next page to

   : MARGIN   CR  15 SPACES ;

your letter will look a little better on the screen.
*ln2
The Dictionary   Page-16
*ln2
Blazin' Forth normally allows 31 characters to be saved in a definitions name. (This is the number specified by the 83 standard.) However, should you prefer fewer characters to be saved, you can do this by changing the value of the variable WIDTH . For example, to have Blazin' Forth save only three characters of your definitions names, type 3 WIDTH !
*ln2
Say-What?
*ln2
  Regarding the second foot-note on page-18. The Forth-83 ." will not execute outside of a colon definition. Forth-83 provides the word .( for the occasions when you need to display strings outside of colon definitions. Use it like this:

   .( PRINT ME )
*ln2
*cn1;Chapter-2*cn0
*ln2
The handy hint on page-50 is a little notorious. I have, personally, never seen a system on which this definition would work. .S is never the less a very handy word, and Blazin' Forth contains it, already compiled into the system. Note that the extra 0 won't be there - you see only what's on the stack, or you get a message "STACK EMPTY", if nothing is on the stack.
*ln2
*cn1;Chapter-3*cn0
*ln2
    Blazin' Forth's editor is a "Starting-Forth-Clone". You will be able to follow this chapter pretty much as it stands. One very important point - you must issue the command MOUNT , to initialize the virtual memory system, before using any words that access the disk - like LIST , for example. Just remember to type MOUNT , and you will be OK . (You only have to give this command once - at the start of your editing session, unless you change disks, issue the command RESTART, or inadvertantly cause a disk error.)
    Some general points: Brodie likes to keep his screen numbers high - in the 100's or 200's . Note that if you have a dual drive, such as a 4040 or MSD , you will have no problem with these high screen numbers ( of course, you will have to have a disk in drive 1!). However, if you are using the system with a single disk drive, such as a 1541, then the highest screen that can be accessed from that drive is 165 . Just keep all your screen numbers below this value, and you will be OK .
     The WIPE command is very important, never edit a new screen without using this command first! It's so important, that Blazin Forth contains the word W , which is just a short way to perform a WIPE . Works just the same.
     Finally, due to the characteristics of the 64's operating system, trailing blanks are suppressed, and not passed to the editor. This means, for example, that Brodies example of blanking a line:

   P bb <return>

won't work. Trailing blanks must be followed by an ^ character in order to be received by the editor. For example:

  P bb^ ( blanks current line )
  U bb^ ( blanks line under current line)

That's enough for now - check back here when you get to FLUSH.

In Forth-83, FLUSH and SAVE-BUFFERS are not quite the same. Both save any updated blocks to the disk, but FLUSH will "hose down" the buffers - if you want to access the same blocks again, Forth will have to re-read them. SAVE-BUFFERS will leave all the blocks current - Forth won't have to re-read them if you need to access them again. Also, Blazin' Forth contains an additional comment word, // , which can be used to include 1 line comments in source screens.
*ln2
Getting Loaded    Page-81
*ln2
The suggestion here is not really very good. If the source for your text takes up more than one block, the best solution is not to use many load commands, as Brodie suggests, but to use THRU .
     THRU takes two numbers on the stack. The first number is the first screen to load, and the second number is the last screen to load. THRU will then load these two screens, and all screens in between.
     So, instead of putting 180 LOAD   181 LOAD  182 LOAD on your load screen, use:

180 182  THRU

instead. It's really much better.
*ln3
*cn1;Chapter 4*cn0
*ln3
A Closer Look at IF . Page-95

  One of the big differences between the 83 standard and earlier Forths is that Forth-83 returns a negative 1 ( -1 ) instead of 1 when the result of a test like 0= or 0< is true. So Brodies examples will look like this:

5 4 > . -1  OK
5 4 < . 0   OK

NOT works differently too. In earlier Forths, it was really just another name for 0= . But in Forth-83, it returns the ones-compliment of the number on the top of the stack. Notice that the '83 NOT still reverses the value of the '83 flags:*ln2
-1 NOT . 0 OK
0 NOT . -1 OK
*ln2
But NOT won't change any non-zero value to false ( 0 ) like the older NOT would:*ln2
1 NOT . -2  OK
*ln2
And, of course, FORTH will still regard -2 as being TRUE , since it isn't zero.

So when upgrading programs, or reading books that talk about earlier Forth systems, keep this in mind. On the other hand, if you're not quite sure what all this means, and want to play it safe, just replace every pre-83 NOT with 0= , and you'll be OK .
*ln2
A Little Logic    Page-97
*ln2
To upgrade these examples to FORTH-83, just replace every occurance of 1 with -1 , and you'll have a Forth-83 example. While we are on the subject, Blazin' Forth contains the two flags pre-compiled as constants. TRUE leaves a true value (-1) on the top of the stack, and FALSE leaves a false value ( 0 ). You'll appreciate this more when you learn about constants later in the book.
*ln2
Two Words with built in IFs  Page 102
*ln2
Just a note - if you do want to add stack checking to your application, all you need to add in Blazin' Forth is the word ?STACK . The ABORT" isn't needed, since ?STACK itself contains the necessary ABORT" .
*ln2
Problems   Page-104
*ln2
Problem 5
Actually, in Forth-83, 0 STARS won't print just one star, but 65,535 stars. Brodies answer ( or the one you cook up for yourself) should fix this problem, but there are better ways. More on this when we get to the chapter on LOOPs. Incidentally, if you tried 0 STARS before reading this note, you can get control of things by hitting RUN/STOP RESTORE , just like in BASIC .
*ln2
Chapter-5

The Return Stack

Page-110

The definitions for I , I' and J are not correct for Forth-83. I' does not exist, and I and J are both defined differently. Don't worry, they still do what they are supposed to (which is return the current index value of a loop), it's just that they don't do what Brodie says they would. Just wait till chapter 6 for more information on these two words.

The correct word to copy the top of the return stack is R@ in Forth-83. (i.e. R@ does what Brodie says I should do.)

Page-111

The phrase >R SWAP I would be >R SWAP R@  in Forth - 83. Both phrases will crash the system

Page-112

The definition of QUADRATIC should be:

   : QUADRATIC ( A B C X -- N )
         >R SWAP ROT R@ * + R> * + ;

In other words, R@ should be used instead of I . See the note above for an explanation.

Page-119

The footnote on this page contains a typo in my copy. The correct definition is:*ln2
     : R%   50 */  1+  2/ ;
*ln2
Problems

Problem 1

In the answer to this problem, Brodie means NEGATE , not MINUS .

You might also notice that Blazin' Forth does not return a -17 like Brodie says it should. This is due to the 83-standards use of floored division. In floored division, numbers are always truncated to the next lower value. To get the same result as Brodie in 83-Forth systems, use ABS and then NEGATE.
*ln2
*cn1;Chapter 6*cn0
*ln2
Forth-83 uses a new loop structure which is very fast, but differs in a few points from the older loops u...
Zgłoś jeśli naruszono regulamin