Next: , Previous: CREATE..DOES> applications, Up: User-defined Defining Words


5.9.8.2 The gory details of CREATE..DOES>

DOES>       compilation colon-sys1 – colon-sys2 ; run-time nest-sys –         core       “does”

This means that you need not use CREATE and DOES> in the same definition; you can put the DOES>-part in a separate definition. This allows us to, e.g., select among different DOES>-parts:

     : does1
     DOES> ( ... -- ... )
         ... ;
     
     : does2
     DOES> ( ... -- ... )
         ... ;
     
     : def-word ( ... -- ... )
         create ...
         IF
            does1
         ELSE
            does2
         ENDIF ;

In this example, the selection of whether to use does1 or does2 is made at definition-time; at the time that the child word is CREATEd.

In a standard program you can apply a DOES>-part only if the last word was defined with CREATE. In Gforth, the DOES>-part will override the behaviour of the last word defined in any case. In a standard program, you can use DOES> only in a colon definition. In Gforth, you can also use it in interpretation state, in a kind of one-shot mode; for example:

     CREATE name ( ... -- ... )
       initialization
     DOES>
       code ;

is equivalent to the standard:

     :noname
     DOES>
         code ;
     CREATE name EXECUTE ( ... -- ... )
         initialization

>body       xt – a_addr         core       “to-body”

Get the address of the body of the word represented by xt (the address of the word's data field).