Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Database

The Forth Column


APR88: THE FORTH COLUMN

The Ninth Forth Modification Laboratory (FORML) Conference was well attended and well worth going to. It was held on a beautiful Thanksgiving weekend in Monterey, Calif., and you could watch the pelicans migrating southward along the Pacific Coast and see swarms of Monarch butterflies hanging from the trees.

As usual, there were two days of solidly packed presentations, with wine and cheese in the evenings. Stephen Sjolander presented a Novix 4016 decompiler that would be of great value to anyone working with this chip. Bob La Quey pointed out that Forth would be an excellent language for implementing Hypertext. George Shaw presented the most complete and comprehensible paper on QUANs (multiple code field words) that I have ever seen. Stephen Pelc showed an implementation of record and field defining words, and Dr. Ting shared a short recursive line-drawing algorithm. This year, Dr. Ting presented even more papers (four) than Wil Baden (three)!

There were many other high-quality papers that you will be able to read in the 1987 FORML Conference Proceedings, available from the Forth Interest Group ([408] 277-0668) later this year. Speaking of that, the Proceedings of the 1987 Rochester Forth Conference is now available as The Journal of Forth Application and Research (JFAR), vol. 5, no. 1, 1987, from the Institute of Applied Forth Research, 70 Elmwood Ave., Rochester, NY 14611. Or you can order it indirectly from FIG.

The informal theme of FORML this year seemed to be BLOCKs vs. text files. Each attendee received a copy of Tom Zimmer's PF Forth (formerly ZF Forth and soon to be FF Forth). Tom's IBM PC public-domain dialect is the joint effort of Zimmer, Smith, Curley, and Modrow. It is enormous by Forth standards, occupying 1 Mbyte of disk space. It includes source files for dozens of utilities. You can get an ARCed copy from the GENie Forth bulletin board (see DDJ, December 1987). Expect to spend a lot of weekends learning it.

PF Forth keeps all its source in text files and includes a sophisticated file editor. The program image is in a .EXE file, and headers are kept in a separate segment. It is closely related to Mike Perry's unpublished F83Y. Mike is the Perry behind the Laxen/Perry F83 dialect. (Henry Laxen has, for the moment, died and gone to C.)

In Mike's own words: "ln an additional attempt to merge with the environment, explore the trade-offs, and generally ingratiate myself with certain fanatic elements, I discarded BLOCK. Don't worry, it's still available as a loadable option. When a file is loaded, it is read into the current file segment with a single call to DOS, then interpreted. Note the 64K limit. All control characters and blanks are treated as whitespace. This allows a single compare to be used. Compilation is quite fast compared to whatever I used to use.

The first ever Australian Forth Symposium will be held May 19-20, 1988, at the NSW Institute of Technology. The focus is on productivity, and there will be papers, demonstrations, and hands-on instruction. Chuck Moore will be there. If you want to go, ring Jose Alfonso or Dr. Walker on (02)20930 or Roy Hill on (02)217-3828.

The next ANSI X3J14 Forth standards meeting is also in May, somewhere in the Northeastern United States. Contact me for details if you would like to attend. You can reach me at Forth Inc., 111 N. Sepulveda Blvd., Manhattan Beach, CA 90066.

At the second ANSI Forth meeting (November 1987), preparations were made for accepting technical proposals. A copy of the approved proposal form is on page 132. About two dozen proposals have been received and many more are sure to follow. There seem to be roughly a dozen technical issues: vocabularies, mass storage, flow of control, arithmetic, documentation requirements, testing, assemblers, controlled reference word set, ROM ability, host and file structure, the interpreter, Tick > BODY and addressability, numeric output, and exception handling.

Figure 1: Approved ANSI Forth proposal form

Filling out the "ANSI ASC X3/X3J14 Technical Proposal" form

Page: Please number each page of your proposal

Title: A short phrase that characterizes your proposal on this subject, please list their titles and dates.

Related Proposals: If you have submitted other proposals on this subject, please list their titles and dates.

Proposal(): Are you proposing a specific change? Then Check the Proposal box.

Comment(): Otherwise, check the comment box.

Keyword(s): Pick a keyword that helps others understand what area of Forth your proposal addresses. For example, Kernal, double integers, system word set...

Forth words(s): List all affected Forth words, including ones added or deleted by your proposal or discussed in your comments.

Abstract: Briefly convey the nature of your proposal (or comment).

Proposal: State your proposal in specific terms. When proposing a new word, or changes to an existing word, simply state the new definition. Include a stack picture if appropriate.

Discussion: If you are making a comment, put it here. If you are submitting a proposal, provide compelling arguments in favor of your proposal. BE concise. If you are aware of arguments against your proposal, state them and rebut them. Is your proposal consistent with current Forth conventions? Does the proposal involve hardware or other system dependencies? Does it affect application portability? Does it have implications for multi-user environments? Should the proposed change be mandatory? Does it affect ROMability? Is it general purpose? How does it affect execution speed? How does it affect compilation speed? What are its memory requirements?

Submitted by: Provide your name, address, adn daytime phone number.

Use the "ANSI ASC X3/X3J14 Technical Proposal Form, cont's" form if additional pages are needed. Remember to put page numbers and repeat the "Submitted by" and "Date" fields on each page.

Each member of the ANSI Forth committee will prepare a position paragraph on each issue. One member, the "magnet," will collect all the paragraphs and synthesize them into one paper describing the different sides of the issue. You can follow or participate in the discussion on any issue by signing onto the GENie Forth bulletin board, Category 10, Forth Standards. I'm told that several hundred people have already perused this category.

Two New Books on Forth

You will find the new Dr. Dobb's Toolbook of Forth, Volume II, to be an excellent anthology of papers on Forth programming techniques. Inside, you can find Bresenham's algorithm, FFTs, spreadsheets, and Logo, all implemented in Forth. Some papers are taken from FORML and Rochester proceedings, and others first appeared here in DDJ. Unfortunately, credit is not given to the original publication. There are 32 quality papers in all, many of them with source code. The Toolbook sells for $29.95 and is available from DDJ ([800] 533-4372 or [800] 356-2002 in California). If you don't want to type in the programs, you can get them on a disk for an additional $25.

Dick Pountain's Object-Oriented Forth (Academic Press, 1987; $19.95) begins: "Forth is, regrettably, one of the best kept secrets in the computing world." In this book, Dick extends Forth to include named objects, which increases its readability and reusability. In essence, an object is a defining word used to create defined words called instances. An instance has its own hidden data structure, made of instance variables, and a set of permitted operations, called methods. Instance variables are to instances as user variables are to tasks.

When an object is defined, all instance variable and method names are removed from the Forth dictionary by relinking the headers. Only the object itself can find them because it has the initial link, or "key," to the hidden vocabulary. All instances of this object are state smart and know the key. During compilation an instance looks the following method up in its private dictionary and compiles a reference to it.

As an example, consider complex numbers as objects. They might have instance variables for the real and imaginary parts and methods for addition, multiplication, and so on. Pountain limits his methods to @ and !, however, so that complex results are left where they belong, on the stack:

TYPE> COMPLEX
    2 VAR REAL
    2 VAR IMAG
OPS>
    :COM! IMAG ! REAL!;
    :COM@ REAL@ IMAG@;
ENDTYPE> COMPLEX

COMPLEX X 2 3 X COM!

Object-Oriented Forth (OOF?) takes you through this and other abstract data types, including lists and heaps. This book is not for beginners, and I highly recommend it.

Dead Duck's Hard Beak

Starting in the October 26, 1987, issue of Info World, Steve Gibson ran three articles in his Tech Talk column describing the implementation of Microsoft's QuickBASIC 4.0. According to Mr. Gibson, "The technology is known as `Threaded PseudoCode' ... and was first seen in the strange powerful language Forth." He continues, "Forth is the language you want to pretend doesn't exist because it's horrible to write with but hauntingly powerful."

Needless to say, these comments drew immediate rebuttal from the Forth community. Here is a sample, translated from Timothy Huang's Chinese Forth column: "... the term Threaded PseudoCode was used repeatedly with such an envious attitude, like a human being who just discovered the warmth of the sun. In fact, we have been using this technique for more than ten years. So why doesn't Mr. Gibson and Microsoft, as well as the whole computer industry, come straight out and recognize FORTH, and quit behaving like a dead duck with a very tough beak?"

Text from BLOCKs

In my last column, February 1988, I presented command for reading and writing data and text files from BLOCKs. Some of the source screens needed fixing, and you will find corrected versions in this month's Listing One, page 94.

The new GETTEXT includes the flow-of-control construct BEGIN...WHILE...WHILE...REPEAT. This construct occurs naturally in both string and file applications:

BEGIN (Are there more characters?)
WHILE (Is this one that you want?)
WHILE ( Go ahead and use it.)
REPEAT

Note that this is a proper structure, delimited by BEGIN at one end and REPEAT at the other.

In most Forths, the stack is used at compile time to hold fix-up addresses until they can be resolved. ; In some dialects, such as polyFORTH and ZEN, only these addresses are on the stack. Furthermore, WHILE swaps addresses to keep the BEGIN address on top. BEGIN...WHILE...WHILE.. REPEAT can be implemented simply by adding THEN to resolve the second WHILE, as in BEGIN... WHILE... WHILE. . .REPEAT THEN.

Other Forths, especially those descending from FIG Forth, keep extra flags on the stack for "compiler security." If BEGIN. . WHILE.. .WHILE...REPEAT does not work for your Forth, you can change it to the less elegant construct:

BEGIN (Any more characters?)
DUP IF DROP (Want this one?)
THEN WHILE ( Eureka! Use it.)
REPEAT

[LISTING ONE]

<a name="00c9_0009">

SCR# 0

( Corrected source screens)
                                                                                                     The following four screens contain corrected source for the operators  GETDATA PUTDATA and PUTTEXT.  The original uncorrected versions are in the DDJ
Forth column, Feb 1988.

Screen 5 defines GETDATA using
BEGIN ... DUP IF  DROP ... THEN WHILE ... REPEAT
instead of the preferred
BEGIN ... WHILE ... WHILE ... REPEAT THEN


SCR# 1

\ Read BLOCKed file as data file

                                                                                                : GETDATA ( a n - n2)
\ reads n bytes of data from input file into address, n < 64K
\ Returns n2 bytes not read ( ie beyond end of file ).
    ( calculate # of bytes to move < 64K : )  POSITION 2@
    BEGIN  2 PICK ( n ) DUP
      IF ( n ) >R  2DUP 1K UM/MOD  SWAP DROP  1+  1K UM*
         CAPACITY 2@ DMIN  2OVER D- 0= NOT OR  R> UMIN
      THEN  ?DUP
    WHILE  >R  2DUP 1K UM/MOD  BLOCK +  4 PICK R@ CMOVE
     R@ 0 D+  2SWAP  R> /STRING  2SWAP
    REPEAT  POSITION 2!  SWAP DROP ;

SCR# 2

                                                                                                                                                                                                                             \ Write BLOCKed file as data file
                                                                                               : PUTDATA ( a n)
\ writes n bytes of data to output file from address, n < 64K
   ( extend the file as needed : )
   DUP 0  POSITION 2@ D+  CAPACITY 2@  2OVER D-  DUP 0<
   IF  2DUP DABS EXTEND  2OVER CAPACITY 2!  THEN  2DROP 2DROP
   ( calculate # of bytes to move < 64K : )  POSITION 2@
   BEGIN  2 PICK ( n ) DUP
      IF ( n ) >R  2DUP 1K UM/MOD  SWAP DROP  1+  1K UM*
         CAPACITY 2@ DMIN  2OVER D- 0= NOT OR  R> UMIN
      THEN  ?DUP
   WHILE  >R  2DUP 1K UM/MOD  BLOCK +  4 PICK SWAP R@ CMOVE
      R@ 0 D+  2SWAP  R> /STRING  2SWAP   UPDATE
   REPEAT  POSITION 2!  2DROP ;

SCR# 3


 0 \ Read text file with #EOF
 1
 2 : GETTEXT ( a n - n2 f)   POSITION 2@   0 ( f ) >R
 3 \ reads n bytes of text from input file into address, n < 64K
 4 \ Returns n2 bytes not read ( ie end-of-line or beyond file)
 5 \ Returns true if #EOL terminates line; false otherwise.
 6    BEGIN  2DUP CAPACITY 2@ D<  3 PICK ( n ) AND
 7    WHILE  2DUP 1K UM/MOD  BLOCK + C@ ( get ch)
 8        DUP  #EOL =    DUP R> OR >R
 9        OVER #EOF = OR NOT  AND ?DUP
10    WHILE  >R  1 0 D+  2SWAP  R> 2 PICK C!  1 /STRING  2SWAP
11    REPEAT THEN   2DUP CAPACITY 2@ D<
12    IF  2DUP 1K UM/MOD  BLOCK + C@  #EOL = DUP D-  THEN
13    2DUP CAPACITY 2@ D<
14    IF  2DUP 1K UM/MOD  BLOCK + C@  #LF  = DUP D-  THEN
15    POSITION 2!  SWAP DROP  R> ;


SCR# 4

 0 \ Read text file without #EOF
 1
 2 : GETTEXT ( a n - n2 f)   POSITION 2@   0 ( f ) >R
 3 \ reads n bytes of text from input file into address, n < 64K
 4 \ Returns n2 bytes not read ( ie end-of-line or beyond file)
 5 \ Returns true if #EOL terminates line; false otherwise.
 6    BEGIN  2DUP CAPACITY 2@ D<  3 PICK ( n ) AND
 7    WHILE  2DUP 1K UM/MOD  BLOCK + C@ ( get ch)
 8       DUP  #EOL =    DUP R> OR >R
 9                      NOT  AND ?DUP
10    WHILE  >R  1 0 D+  2SWAP  R> 2 PICK C!  1 /STRING  2SWAP
11    REPEAT THEN   2DUP CAPACITY 2@ D<
12    IF  2DUP 1K UM/MOD  BLOCK + C@  #EOL = DUP D-  THEN
13    2DUP CAPACITY 2@ D<
14    IF  2DUP 1K UM/MOD  BLOCK + C@  #LF  = DUP D-  THEN
15    POSITION 2!  SWAP DROP  R> ;


SCR# 5
 0 \ Read text file with #EOF
 1
 2 : GETTEXT ( a n - n2 f)   POSITION 2@   0 ( f ) >R
 3 \ reads n bytes of text from input file into address, n < 64K
 4 \ Returns n2 bytes not read ( ie end-of-line or beyond file)
 5 \ Returns true if #EOL terminates line; false otherwise.
 6    BEGIN  2DUP CAPACITY 2@ D<  3 PICK ( n ) AND
 7    DUP IF  DROP  2DUP 1K UM/MOD  BLOCK + C@ ( get ch)
 8            DUP  #EOL =    DUP R> OR >R
 9            OVER #EOF = OR NOT  AND ?DUP  THEN
10    WHILE  >R  1 0 D+  2SWAP  R> 2 PICK C!  1 /STRING  2SWAP
11    REPEAT THEN   2DUP CAPACITY 2@ D<
12    IF  2DUP 1K UM/MOD  BLOCK + C@  #EOL = DUP D-  THEN
13    2DUP CAPACITY 2@ D<
14    IF  2DUP 1K UM/MOD  BLOCK + C@  #LF  = DUP D-  THEN
15    POSITION 2!  SWAP DROP  R> ;




-30-










Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.