Next: Quotations, Previous: Colon Definitions, Up: Defining Words [Contents][Index]
Sometimes you want to define an anonymous word; a word without a name. You can do this with:
:noname ( – xt colon-sys ) core-ext “colon-no-name”
This leaves the execution token for the word on the stack after the
closing ;. Here’s an example in which a deferred word is
initialised with an xt from an anonymous colon definition:
Defer deferred :noname ( ... -- ... ) ... ; IS deferred
Gforth provides an alternative way of doing this, using two separate words:
noname ( – ) gforth-0.2 “noname”
The next defined word will be anonymous. The defining word will
leave the input stream alone. The xt of the defined word will
be given by latestxt, the nt by latestnt.
latestxt ( – xt ) gforth-0.6 “latestxt”
xt is the execution token of the last word defined in the current section.
The previous example can be rewritten using noname and
latestxt:
Defer deferred noname : ( ... -- ... ) ... ; latestxt IS deferred
noname works with any defining word, not just :.
latestxt also works when the last word was not defined as
noname. It does not work for combined words, though, use
latestnt. It also has the useful property that it is valid as
soon as the header for a definition has been built. Thus:
latestxt . : foo [ latestxt . ] ; ' foo .
prints 3 numbers; the last two are the same.
Next: Quotations, Previous: Colon Definitions, Up: Defining Words [Contents][Index]