| www.delorie.com/gnu/docs/gforth/gforth_106.html | search |
![]() Buy GNU books! | |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
CREATE..DOES> doc-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
|
doc->body
| webmaster donations bookstore | delorie software privacy |
| Copyright © 2003 by The Free Software Foundation | Updated Jun 2003 |