bouma@cs.purdue.EDU (William J. Bouma) (05/10/89)
In article <5096@tekgvs.LABS.TEK.COM> toma@tekgvs.LABS.TEK.COM (Tom Almy) writes: >In article <6716@medusa.cs.purdue.edu> bouma@cs.purdue.EDU (William J. Bouma) writes: >>standard. It was really stupid , since all I had to do to make recursion >>work in the thing was to put the word being defined into the dictionary as >>soon as it was seen, rather than after the definition was complete. The > > >There is a good reason *not* to make a word be visible in the dictionary >before it is seen -- sometimes it is nice to be able to redefine a >word in terms of itself. As an example: > >: / DUP 0= IF ." ATTEMPT TO DIVIDE " DROP . ." BY ZERO" ABORT THEN / ; > I do not agree with this reasoning. It seems like redefining a word in terms of itself is a more unusual case than is recursion. Thus it should have to suffer the unnatural syntax rather than the recursion. In my system I do it like this: : / DUP 0= IF ." ATTEMPT TO DIVIDE " DROP . ." BY ZERO" ABORT THEN '' / ; where '' just grabs the next word and gets its old definition. Of course either way will work, but I see no "good reason" not to do it my way. >There is a nice feature in Laboratory Microsystem's Forths (and others) >that allows forward referencing of colon definitions and thus mutually >recursive words. It is used in this way: > >F: WORD-B >: WORD-A ... WORD-B ... ; >R: WORD-B ... WORD-A ... ; Durring a colon definition, I just put all undefined words in the dictionary with their code fields pointing at code that traps an error and prints " undefined word executed WORD ". This eliminates the need for any special mechanism for mutual recursion. When WORD-B is finaly defined, the code pointer is just changed to point at the current code (as any normal re- definition). -- Bill <bouma@cs.purdue.edu> || ...!purdue!bouma
ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) (03/08/91)
Category 3, Topic 13 Message 12 Thu Mar 07, 1991 FIGCHAPTERS [Elliott] at 14:44 EST A prol problem that frequently seems to come up with recursion is stack overflow. If the recurson is of a fairly simple type it seems to me that stack garbage collection can be built in. ----- This message came from GEnie via willett. You *cannot* reply to the author using e-mail. Please post a follow-up article, or use any instructions the author may have included (USMail addresses, telephone #, etc.). Report problems to: dwp@willett.pgh.pa.us _or_ uunet!willett!dwp