home .. forth .. colorforth mail list archive ..

Re: [colorforth] DOES> How is colorForth different from other Forths?


That really doesn't do justice to what DOES> is (although it is
correct). I'd be more inclined to word a definition like this:

In ANS Forth, DOES> can be used to create a class of words that all
perform the same actions on the data set in their parameter field.
VARIABLE and CONSTANT being simple examples:

: VARIABLE ( -- ) CREATE 0 , DOES> ( -- a ) ;
: CONSTANT ( n -- ) CREATE , DOES> ( -- n ) @ ;

However, this can be used to define far more powerful classes of
words. For example, here's a word that takes the current dictionary
pointer, stores it and when called compiles a CALL to itself:

: T_CODE ( -- ) CREATE HERE CELL+ , ASSEMBLER
  DOES> ( -- ) @ [ASM CALL ASM] ;

See how this word can be used to define code words now:

T_CODE 4+
    4 # EBX ADD
    RET
END-CODE

Trivial example, but it gets the point across. I take for god-send
that your definition of the colors in colorForth are correct :),
but they only reproduce your defined classes of words. They don't
detail how to use colorForth to produce the effect of T_CODE.

Jeff

Saturday, December 13, 2003, 11:08:56 AM, you wrote:

RP> Rough draft   please edit:
In forth  " DOES>>  "   Changes the action of the last created word to get
RP> it's parameter address and place it on the data stack then execute words
following " DOES>> ".

RP> : VARIABLE ( - ) CREATE  0 , DOES> ( - a )  ;
RP> : CONSTANT ( n - ) CREATE   ,  DOES> @  ( - n ) ;
RP> : ARRAY ( n - ) CREATE  ALLOT  DOES>  +  ( - a ) ;

RP> In  color forth  variable is provided with magenta word
RP> which  makes a macro entry that defers the source  variable object address
RP> as a constant and a forth entry that puts the  source variable object
RP> address on the data stack.
RP> I colorForth constant is  yellow words computing the value of the constant a
RP> red word, creating a program entry,  and a green ;   deferring top of stack
RP> as a literal and
RP> deferring exit.



---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@xxxxxxxxxxxxxxxxxx
For additional commands, e-mail: colorforth-help@xxxxxxxxxxxxxxxxxx
Main web page - http://www.colorforth.com