[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

go and return-from inside unwind-protect cleanup



    Date: Wed, 25 Sep 85 22:01 EDT
    From: David A. Moon <Moon@SCRC-STONY-BROOK.ARPA>

	Date: Mon, 9 Sep 85 13:01 EDT
	From: Guy Steele <gls@THINK-AQUINAS.ARPA>

	    Date: Mon, 9 Sep 85 09:43 EDT
	    From: David C. Plummer in disguise <DCP@SCRC-QUABBIN.ARPA>

	    Are the following legal?

		    (defun foo (go-p)
		      (prog nil
			 tag
			    (unwind-protect
				(return (compute))
			      (if go-p (go tag)))))

		    (defun bar (return-p)
		      (prog nil
			 tag
			    (unwind-protect
				(progn (compute)
				       (go tag))
			      (if return-p (return nil)))))

	I regard both of these as completely legal.

    While they may be legal and implementable, I feel that this programming
    style should be strongly discouraged.  For one thing, it can be
    rather difficult to stop the execution of (FOO T), since any attempt
    to THROW out of it will simply cause it to re-enter its infinite loop.

I agree that GO should not be used capriciously, especially in company
with UNWIND-PROTECT.  (For some *really* awful code of this type, see
the early SCHEME papers.)

I do think that the interaction between GO/RETURN and UNWIND-PROTECT
should be well-defined, however, because of the following kind
of situation:

(DEFMACRO HAIRY-PROTECTED-MACRO-WITH-BODY (...)
  `(UNWIND-PROTECT (PROGN ... ,@BODY)
     ...))

(TAGBODY
   ...
   (HAIRY-PROTECTED-MACRO-WITH-BODY
     ...
     (WHEN (GROSS-ME-OUT) (GO LOSE))
     ...)
   ...
 LOSE (ERROR "I am grossed out."))

The GO ought to work more-or-less as expected; you shouldn't have to
know that the macro has an UNWIND-PROTECT in it.  On the other hand, the
UNWIND-PROTECT must do its job of protecting things, and shouldn't have
to know anything special about a GO being in its body.

--Guy