Subject: Re: throw and catch...
From: Erik Naggum <erik@naggum.no>
Date: 1999/06/21
Newsgroups: comp.lang.lisp
Message-ID: <3138962515282167@naggum.no>

* David Bakhash <cadet@acs.bu.edu>
| First off, what I'm doing is non-standard (it uses multiprocessing).  I
| have a loop which runs forever.  I would like to be able to break out of
| it at any time, execute whatever protected forms were necessary, and then
| get out of there.  But I want to be able to do it from a remote part of
| the Lisp world (i.e. a totally separate thread).  Basically, like throw
| and catch, but not so strict on the lexical/dynamic restrictions.

  I do this all the time.  here's how.  in process A, you have:

(catch 'interrupt
  (loop ...))

  you need a function INTERRUPT

(defun interrupt (&optional value)
  (ignore-errors (throw 'interrupt value)))

  now you can do

(process-interrupt <process-A> #'interrupt <value>)

  assuming, of course, you have something like Symbolics' multiprocessing,
  such as supported by Allegro CL.  note that INTERRUPT actually executes
  in process A, i.e., inside the proper dynamic environment.  (you want the
  IGNORE-ERRORS because you have no idea what process A is doing when it is
  asked to run this function, and you might execute entirely unexpected
  error handlers if you try to throw to a tag not in scope at the time.)

#:Erik
-- 
@1999-07-22T00:37:33Z -- pi billion seconds since the turn of the century