Subject: Re: CREATE <BUILDS



> Could someone enlighten me on why one would use CREATE ... DOES> in
> some instances and <BUILDS .. DOES> in others?

<BUILDS is an anachronism.  The name was changed from <BUILDS to CREATE
in the 79 standard.  There might have been some subtle difference
between the semantics of the old <BUILDS and the new CREATE, but I
can't remember what it was.  In any case, <BUILDS is no longer part
of the current standard, having been replaced by CREATE.

CREATE ought to work fine in place of <BUILDS in your example.

Your example of an execution array to dispatch control keys is
a good one.  Instead of initializing the array with zero, it would
have been better to initialize it with the address of a word that
prints an "unitialized vector" message.

There is a spiffier way to do the control key handling, to wit:

Instead of making an array indexed by the control key typed,
you convert each control character into a string of the form
"^P", for instance, and then search the dictionary for a word
with that name.  If one is found, execute it.  This scheme make
it very easy to define and modify the behavior of various control
keys.  For instance, if you want to define control-H to erase
the previous character, all you have to do is

: ^H erase-previous-character ;

assuming you already have a word "erase-previous-character" which
does the work.

It is also easy to handle escape sequences with this scheme.
You define ^[ ( which is ESCAPE ) to append the next key to
the current string, then search the dictionary again.  For example,

: ^[  key append-char-to-string search-and-execute ;
: ^[H erase-previous-word ;

again assuming you already have the words that do the work.

I wrote a paper describing this scheme and its use to implement
an Emacs-style command-line editor with command-completion.
It is being published in the Proceedings of the 1984 Rochester
Forth Conference.  Code is included.  The Proceedings are being
published now and should be out pretty soon.  The code will require
some hacking for use with Bill's VAX Forth, because it is written
for Forth-83, whereas Bill's Forth is Forth-79.  Shouldn't be too
difficult, though.  The command completion may be difficult, due
to the highly-encoded 5-character + count names that Bill uses.
The line editing should be easy to port.

I will mail the code to anybody that wants it, but it would be a
nice gesture to buy the Proceedings anyway (Support your Institute for
Applied Forth Research!).

Mitch Bradley

---
My recent posting describing QUAN's and TO variables generated
a lot of mail response, so I'll follow up by posting a list of
references.

Briefly, QUAN's, or more generally, Multiple Code Field words,
are words which have several behaviors, depending on a word
which precedes them.  The particular behavior is selected at
compile time:

Examples:

A QUAN is sort of like a variable.

  QUAN FOO   defines FOO as a QUAN

  FOO        leaves the value of FOO on the stack
  47 TO FOO  stores 47 into FOO
  AT FOO  leaves the parameter field address of FOO on the stack

A VECT is sort of like an execution variable (or execution vector or
deferred word).

  VECT FOO   defines FOO as a VECT

  FOO            executes the word associated with FOO
  ' EMIT TO FOO  associates the word EMIT with FOO
  AT FOO         leaves the parameter field address of FOO on the stack

The word IS has been proposed as an alternative to TO because
TO is difficult to distinguish from the number 2 when talking to
someone.

Several very good papers about Multiple Code Field words are to be
found in Volume 1, No. 2 of The Journal of Forth Application and
Research.  I believe that this issue is still available; write to
"Journal of Forth Application and Research", Box 27686, Rochester, NY
14627.

For historical background, see

P. Bartholdi, "The TO solution" and "TO solution continued",
FORTH Dimensions, Vol. 1, Nos. 4 and 5, 1979.

G.B. Lyons, "Note on the TO solution", FORTH Dimensions,
Vol. 1, No. 5, 1980

E. Rosen, "High Speed, Low Memory Consumption Structures",
Proceedings FORML Conference 1982.

W. Ragsdale, "A New Syntax for Defining Defining Words",
Proceedings FORML Conference 1980, p. 122

In particular, I recommend the "Journal" issue and the Rosen paper.

I'm not sure who first realized that Multiple Code Field words are
similar in concept to "objects", but several people at the recent
Rochester Forth Convention seemed to have hit upon the notion.
This notion is ripe for exploitation right now.  Please let me know if
you do anything with it.

Mitch Bradley