Path: utzoo!utgpu!watserv1!watmath!att!dptg!ulysses!andante!mit-eddie!uw-beaver!cornell!batcomputer!rpi!zaphod.mps.ohio-state.edu!usc!ucsd!ucbvax!MITCH.ENG.SUN.COM!wmb From: wmb@MITCH.ENG.SUN.COM Newsgroups: comp.lang.forth Subject: Re: Safety Nets Message-ID: <9007161525.AA14635@ucbvax.Berkeley.EDU> Date: 16 Jul 90 03:28:15 GMT Sender: daemon@ucbvax.BERKELEY.EDU Reply-To: wmb%MITCH.ENG.SUN.COM@SCFVM.GSFC.NASA.GOV Organization: The Internet Lines: 27 > NMORGENSTERN writes: > > : 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 .... This is similar to, but slightly weaker than, C's setjmp()/longjmp() . jmp_buf safety1; <==> NET SAFETY1 setjmp(safety1) ~<==> SAFETY1 SET-NET longjmp(safety1); <==> SAFETY1 FALL The reason it is weaker is because setjmp() returns a flag indicating whether it returned normally or returned due to a longjmp(). This feature could be added simply by adding TRUE to the end or SET-NET and FALSE to the end of FALL (or vice versa; either way works). The relative merits of CATCH/THROW vs. setjmp()/longjmp() have already been debated on this newsgroup. Mitch Bradley