home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.forth
- Path: sparky!uunet!cs.utexas.edu!zaphod.mps.ohio-state.edu!darwin.sura.net!uvaarpa!murdoch!fermi.clas.Virginia.EDU!jvn
- From: jvn@fermi.clas.Virginia.EDU (Julian V. Noble)
- Subject: Re: Implementing Algolic algorithms in Forth ?
- Message-ID: <1992Dec29.204909.21524@murdoch.acc.Virginia.EDU>
- Sender: usenet@murdoch.acc.Virginia.EDU
- Organization: University of Virginia
- References: <2498@itexjct.jct.ac.il>
- Date: Tue, 29 Dec 1992 20:49:09 GMT
- Lines: 36
-
- jacobsen@itexjct.jct.ac.il writes:
- > May the Forth wizards help me with that:
- >
- > I want to implement som 'Algolic languages' algorithms. Let's take
- > the Quick Sort algorithm as an example. In that algorithm the programmer
- > must call the sort function (word, procedure etc.) recursivly, with
- > sub-array of the array it got as input.
- > As far as I know, recursion in Forth mean: the ablity of word to use
- > itself. It is working in those cases when the word use only the stack,
- > like a recursive definition of factorial. How may I write a definition
- > like the quick sort one, in Forth.
- >
- > Joel
- Dear Joel,
-
- The short answer is "Get a copy of Scientific FORTH by J.V. Noble (that is,
- my humble self) and read the chapter on recursive programming." The book
- is available (with program diskette) for $49.95 + s/h from
- Mechum Banks Publishing
- P.O. Box 335
- Ivy, Virginia 22945
- USA
-
- The long answer is that you must arrange for the definition that calls
- itself to use a stack to hold its arguments. In quicksort, e.g., the
- arguments are pointers to the list of items to be sorted. The nice thing
- about recursive sorting algorithms is that the stack grows only as
- LOG2(N), where N is the number of items in the list. Thus you don't have
- to worry (much) about stack overflow.
-
- Finally, I am certain that sorting programs have been written (and pub-
- lished!) in Forth, say in Journal of Forth Application and Research or
- Forth Dimensions, or even old Dr. Dobbs's (in the days when they used
- to publish articles on Forth).
-
- Best of luck. Julian V. Noble
-