Path: utzoo!utgpu!watserv1!watmath!att!rutgers!cs.utexas.edu!uunet!willett!ForthNet From: ForthNet@willett.UUCP (ForthNet articles from GEnie) Newsgroups: comp.lang.forth Subject: Advanced Beginners Message-ID: <1339.UUL1.3#5129@willett.UUCP> Date: 15 Jul 90 22:57:56 GMT Organization: String, Scotch tape, and Paperclips. (in Pgh, PA) Lines: 43 Category 2, Topic 8 Message 54 Sun Jul 15, 1990 NMORGENSTERN at 14:53 EDT Re: BOB CAVANAUGH > Can anybody out there give me a way to jump back to a word > after an error condition is set? In many cases a simple loop is enough. For example, if the word DO-IT leaves TRUE on the stack if ok and FALSE if not, you can repeat until satisfactory by this: BEGIN DO-IT UNTIL. If you want to do a fixup, you can use this: BEGIN DO-IT NOT WHILE FIXUP REPEAT These do not permit jumping out of a nested word. Several methods have been proposed that do just that. For example: CATCH THROW, which I believe is in the library. I proposed a method at ACM SIGFORTH, Austin, 1989, which uses 5 words. I have tested it in F83, and it should work in F-PC, but I haven't tried it. The idea is to set a "safety-net" that will catch you if you fall. You can have as many nets as you need, and can change them while the program is running. The method permits a Jump-Back-To a previous point, but you cannot jump forward into. : NET CREATE 0 , 0 , 0 , ; : 3! ( n1 n2 n3 a -- ) 2DUP ! 2+ NIP 2! ; : 3@ ( a -- n1 n2 n3) DUP 2+ 2@ ROT @ ; : SET-NET ( net -- ) R@ SP@ ROT RP@ SWAP 3! ; : FALL ( net -- ) 2+ RP! SWAP >R 4 + SP! ; For example: To declare a net: NET SAFETY1 To set the net ... SAFETY1 SET-NET ( point A ) FOO FAH .... To go back to point A from any word nested within FOO or FAH simply incorporate the phrase SAFETY1 FALL The data stack and return stack will be restored to their original depth and the program will take off from point A. It is possible to incorporate a net in ABORT". The details are given in the Austin paper. I have recently modified this scheme in several ways, mainly to permit recursion, but have not completed all the details. ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or willett!dwp@hobbes.cert.sei.cmu.edu