A definition can be called simply be writing the name of the definition
to be called. Note that normally a definition is invisible during its
definition. If you want to write a directly recursive definition, you
recursive to make the current definition visible.
recursivecompilation -- ; run-time -- gforth ``recursive''
makes the current definition visible, enabling it to call itself recursively.
Another way to perform a recursive call is
recursecompilation -- ; run-time ?? -- ?? core ``recurse''
calls the current definition.
@progstyle I prefer using
recurse, because calling the definition by name is more descriptive (if the name is well-chosen) than the somewhat cryptic
recurse. E.g., in a quicksort implementation, it is much better to read (and think) "now sort the partitions" than to read "now do a recursive call".
For mutual recursion, use
deferred words, like this:
defer foo : bar ( ... -- ... ) ... foo ... ; :noname ( ... -- ... ) ... bar ... ; IS foo
When the end of the definition is reached, it returns. An earlier return can be forced using
EXITcompilation -- ; run-time nest-sys -- core ``EXIT''
Don't forget to clean up the return stack and
primitive compiled by
;s-- gforth ``semis''
Go to the first, previous, next, last section, table of contents.