www.delorie.com/gnu/docs/gforth/gforth_102.html   search  
 
Buy GNU books!


Gforth Manual

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.9.6 Anonymous Definitions

Sometimes you want to define an anonymous word; a word without a name. You can do this with:

doc-:noname

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:

doc-noname doc-lastxt

The previous example can be rewritten using noname and lastxt:

 
Defer deferred
noname : ( ... -- ... )
  ... ;
lastxt IS deferred

noname works with any defining word, not just :.

lastxt also works when the last word was not defined as noname. It does not work for combined words, though. It also has the useful property that is is valid as soon as the header for a definition has been built. Thus:

 
lastxt . : foo [ lastxt . ] ; ' foo .

prints 3 numbers; the last two are the same.


  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003