Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!purdue!decwrl!ucbvax!SCFVM.BITNET!ZMLEB From: ZMLEB@SCFVM.BITNET (Lee Brotzman) Newsgroups: comp.lang.forth Subject: Re: Random comments Message-ID: <8908032041.AA02334@jade.berkeley.edu> Date: 3 Aug 89 16:12:41 GMT References: Sender: daemon@ucbvax.BERKELEY.EDU Organization: The Internet Lines: 88 > >First, my appologies of starting the "real programmer" thread. It was >written tongue-in-cheek, and fit in with the general tone of >talk.religion.computers at the time. Apology accepted. At least it generated a good side-effect -- more traffic in a very slow newsgroup! > >As someone new (less than 1 month, only have one working program - life) >to FORTH, 2 things really bug me. Why is it that we have 2!, 2DUP, 2CONSTANT, >but D. ? It seems inconsistant. You can't use 2 as a prefix across the board >(2+ and 2* are taken) but why not use D? I also mind that DO loops up to, >not including the limit - it's not intuitive. I believe the '2' prefix for double numbers came about because a double number does not always imply a double-length integer. The data item might be a pair of single-length integers, e.g. X-Y coordinates on a grid. While '2' is somewhat appropriate for both situations, 'D' clearly is not. I often use 2DUP to duplicate two single-length values on the stack. DDUP wouldn't "feel" right. But remember, this is Forth. If you don't like a name, then you can always do the following: : D! 2!; : DCONSTANT 2CONSTANT ; : DO SWAP 1+ SWAP [COMPILE] DO ; IMMEDIATE Unless you are distributing source code to the public (in which case the renaming and redefinition of standard words renders the code nearly useless) then I would suggest you put all the redefinitions in a file (or set of blocks depending on your situation) and INCLUDE them whenever you compile. Better yet, you can compile the redefintions and do a SAVE-SYSTEM and they will be there always. >I appreciate all the sugestions and responses to my last post. I'm writing >words to define a "parameter list" without the rest of the definition. It >should let me implement a vectored execution scheme without wasting alot of >space on headers. Any comments?? An off the cuff, thirty-second design phase vectored execution scheme: : EXEC-VECTOR ( compile time: n -- ...number of vectors to allocate ) ( execution: n -- ...number of vector to execute ) CREATE 2* ALLOT DOES> SWAP 2* + @ EXECUTE ; : STORE-VECTOR ( n -- ...cell number to store execution vector into) ( this word is used like: n STORE-VECTOR ) ( where: n is the cell number, is the vector array ) ( and is the word to put in the array ) ' >BODY ( n pfa-to -- ...get pfa of ) SWAP 2* + ( cell-adr -- ...calculate vector cell address ) ' ( cell-adr cfa-from -- ...get cfa of ) SWAP ! ; IMMEDIATE ( store the execution vector ) 10 EXEC-VECTOR ADDS 0 STORE-VECTOR ADDS + 1 STORE-VECTOR ADDS D+ 2 STORE-VECTOR ADDS F+ So, '0 ADDS' will result in '+' being executed, and '2 ADDS' will execute 'F+'. Actually the example isn't very practical. I have used a very similar scheme, however, in a text editor. I have an execution vector array with 128 cells in it. Each cell points to a different editing function. The character entered on the keyboard is the index into the array that specifies which function is being called. So my word EDIT is just: : EDIT GET-FILE ( Open, create, or re-establish like to the file ) INITIALIZE ( set up some stuff to get started ) BEGIN KEY DO-EDIT AGAIN; ( DO-EDIT is the name of the vector array ) Cells which correspond to regular characters, like 'A', execute the word CHARACTER , which stores the character into the file. The cell which corresponds to control-A (decimal 1) executes the word ADDLINE, i.e. when I press control-A, a new line is added to the file being edited. This makes it real easy to reconfigure the editor. Plus I can use forth as an editor macro language, just define a new editing function and tie the CFA to the vector array. > Micha Berger > -- Lee Brotzman (FIGI-L Moderator) -- BITNET: ZMLEB@SCFVM -- Internet: zmleb@scfvm.gsfc.nasa.gov -- The government and my company don't know what I'm saying. -- Let's keep it that way.