Article View: net.lang.forth
Article #142Re: CREATE <BUILDS
From: Mitch Bradley
Date: Sat, 13 Oct 1984 22:04
Date: Sat, 13 Oct 1984 22:04
56 lines
3091 bytes
3091 bytes
> 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
Technical Details
Message-ID:
<1743@sun.uucp>Path:
arc1-ca.pugleaf.net!utzoo!watmath!clyde!bonnie!akgua!sdcsvax!sdcrdcf!hplabs!oliveb!ios!qubix!sun!wmbReferences:
<3068@utah-cs.UUCP>Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84 SMI; site sun.uucp Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!bonnie!akgua!sdcsvax!sdcrdcf!hplabs!oliveb!ios!qubix!sun!wmb From: wmb@sun.uucp (Mitch Bradley) Newsgroups: net.lang.forth Subject: Re: CREATE <BUILDS Message-ID: <1743@sun.uucp> Date: Sat, 13-Oct-84 18:04:15 EDT Article-I.D.: sun.1743 Posted: Sat Oct 13 18:04:15 1984 Date-Received: Mon, 15-Oct-84 01:54:02 EDT References: <3068@utah-cs.UUCP> Organization: Sun Microsystems, Inc. Lines: 56