[stack] Re: disallowing recursive definitions
"pml060912" <[email protected]>
| Newsgroups | gmane.comp.lang.concatenative |
|---|---|
| Message-ID | <[email protected]> |
--- In [email protected], Manfred Von Thun <m.vonthun@...> wrote: > > > > > On 29/2/08 7:39 AM, "John Nowak" <john@...> wrote: > > > > > Recently, I mentioned that if you disallow recursive definitions, then > > definitions can be thought of as macros or rewrite rules. > > > This encourages me to ask a question about Forth which I have been > too shy to ask. I¹ve read a number of times that recursion was not > allowed or not easy to do at least in the earlier versions of > Forth. I explained this to myself like this: the colon definitions are > just macros, and the macro expansion is very simple. > > Was I right about the early Forths? Was is the current situation? Chuck Moore did use macros in some of his early experiments, I believe, but by the time there were enough features for it to be recognisably Forth he had already settled on compiling into indirect threaded code. Other implementation methods followed, and that one is now rare. Google for "history of Forth", which I think is at Forth inc.'s site. The problem with recursion was how the compiler was implemented, but it was usually quite minor. The compiler couldn't recognise a word that was still being compiled, as it hadn't yet been marked in the vocabulary as a successfully compiled word. You had to achieve recursion with a special keyword where you would have put the recursive call, sometimes called MYSELF and sometimes RECURSE, but it wasn't particularly difficult; you could even provide it yourself if it wasn't already there. Where things got a little more awkward was with mutual recursion, which required some set up work with vectors that you used in the main words where you would have had them calling each other. You had to reassign those to the right places after compiling the main words, and calling them usually imposed some more overhead. PML.