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
can use recursive
to make the current definition visible.
recursive
compilation -- ; run-time -- gforth ``recursive''
makes the current definition visible, enabling it to call itself recursively.
Another way to perform a recursive call is
recurse
compilation -- ; run-time ?? -- ?? core ``recurse''
calls the current definition.
@progstyle I prefer using
recursive
torecurse
, because calling the definition by name is more descriptive (if the name is well-chosen) than the somewhat crypticrecurse
. 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 defer
red 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
EXIT
compilation -- ; run-time nest-sys -- core ``EXIT''
Don't forget to clean up the return stack and UNLOOP
any
outstanding ?DO
...LOOP
s before EXIT
ing. The
primitive compiled by EXIT
is
;s
-- gforth ``semis''
Go to the first, previous, next, last section, table of contents.