Deferred words and mutual recursion
Factor handbook » The language » Words

Next:Compiler declarations

Words cannot be referenced before they are defined; that is, source files must order definitions in a strictly bottom-up fashion. This is done to simplify the implementation, facilitate better parse time checking and remove some odd corner cases; it also encourages better coding style.

Sometimes this restriction gets in the way, for example when defining mutually-recursive words; one way to get around this limitation is to make a forward definition.

The class of deferred word definitions:

deferred? ( object -- ? )

Deferred words throw an error when called:
undefined ( -- * )

Deferred words are just compound definitions in disguise. The following two lines are equivalent:
DEFER: foo : foo ( -- * ) undefined ;