Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!usc!ucsd!ucbvax!MITCH.ENG.SUN.COM!wmb From: wmb@MITCH.ENG.SUN.COM (Mitch Bradley) Newsgroups: comp.lang.forth Subject: TEXIT Message-ID: <9102122127.AA04970@ucbvax.Berkeley.EDU> Date: 12 Feb 91 19:09:12 GMT Sender: daemon@ucbvax.BERKELEY.EDU Reply-To: Mitch Bradley Organization: The Internet Lines: 39 > Here's something else which (to my mind) cannot be implemented _efficiently_ > in a portable way using ANS Forth. Even the inefficient ways are difficult. > > : || IF R> DROP -1 THEN ; ( t - t) ( f - ) ( exit on true) > : && 0= IF R> DROP 0 THEN ; ( t - ) ( f - f) ( exit on false) : || POSTPONE DUP POSTPONE IF POSTPONE EXIT POSTPONE THEN ; IMMEDIATE : && POSTPONE DUP POSTPONE 0= POSTPONE IF POSTPONE EXIT POSTPONE THEN ; IMMEDIATE This is efficient in terms of speed, but inefficient in terms of space. I don't think it is particularly difficult. The problem with R> DROP is that it implies detailed knowledge of how the return stack is used for colon definitions. For some Forth hardware and some optimizing compilers, the assumptions made by R> DROP are violated. This is an existing problem that ANS Forth did not create; it simply chose not invalidate those existing Forth implementations by requiring something they could not provide. It will still be possible to use R> DROP on most ANS Forth implementations. From a de-facto standpoint, it will remain about as portable as it has ever been (i.e. reasonably portable). It is possible to use the portable implementations shown above for the "completely-standard" version of your application, and substitute the not-quite-portable versions when running on systems on which they work. This is not a new technique; people do it all the time with CODE word "accelerators" for portable high-level definitions. By the way, I sometimes use CATCH and THROW to implement multiple "bail-out" points, which is what it looks like || and && are trying to solve. CATCH and THROW can be compiled inside colon definitions to make new custom tools like the above. Mitch