🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.forth
Article #283

Mutual recursion in Forth

#283
From: David Phillip Oster
Date: Wed, 12 Mar 1986 18:15
30 lines
1891 bytes
My favorite version of recursion in forth is the way it is done in the
Laxen & Perry Forth-83s.  I'm going to show you how you write a collection
of mutually recursive routines, (which, for me, is much more command
practise than writing a single routine that calls it self recursively.)

DEFER Routine1
DEFER Routine2
DEFER Routine3
: (Routine1) ... do something one ... ;
: (Routine2) .... do sonething two ... ;
: (Routine3) ... do something 3 ... ;
' (Routine1) IS Routine1
' (Routine2) IS Routine2
' (Route3) IS Routine3

The makes the the un-parenthesized named synonyms for the parenthisized names.
Since all the un-parenthesized names are declared before any of the
parenthesized ones I can use all 3 un-parenthesized names in the
definitions of any of the parenthesized names.

Lastly, here is some simple code for DEFER and IS (leaving aside the
issues of user variables and state smartness that are handled by the real
Laxen & Perry code.)
: DEFER CREATE ' , DOES> @ EXECUTE ;
: IS ' >PFA ! ;		\ remember, in F83, "'" returns the CFA!

--- David Phillip Oster
-----------------------  ``What do you look like when you aren't visualizing?''
Arpa: oster@lapis.berkeley.edu
Uucp: ucbvax!ucblapis!oster
Technical Details
Message-ID: <426@ucbjade.BERKELEY.EDU>
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!ucbvax!ucbjade!oster

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site ucbjade.BERKELEY.EDU
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!ucbvax!ucbjade!oster
From: oster@ucblapis.BERKELEY.EDU (David Phillip Oster)
Newsgroups: net.lang.forth
Subject: Mutual recursion in Forth
Message-ID: <426@ucbjade.BERKELEY.EDU>
Date: Wed, 12-Mar-86 13:15:15 EST
Article-I.D.: ucbjade.426
Posted: Wed Mar 12 13:15:15 1986
Date-Received: Fri, 14-Mar-86 05:37:21 EST
Sender: network@ucbjade.BERKELEY.EDU
Reply-To: oster@ucblapis.UUCP (David Phillip Oster)
Organization: University of California, Berkeley
Lines: 30