Discovering Recursion
Forth has a return stack and four types of loops. But does Forth have recursion? It depends on whom you ask. “Clean” FORTH-79 doesn’t directly support recursion. However, you can implement recursion yourself with the help of R>, >R, and similar words. It sounds like a cool do-it-yourself project. If you’re not much into DIY, consider using fig-Forth with the word RECUR (in some dialects, MYSELF)—or, better, revert to Gforth with RECURSIVE.
The word RECURSIVE immediately follows the name in a new word definition. It creates a temporary entry in the dictionary, to which the rest of the definition can refer. If you provide no such entry, attempting to use a word within its definition will cause an Undefined word error. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access