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

Re: toplevel-loop example



>On page 654 in the MCL 2.0 final manual, I am told that you want your
>toplevel function to catch aborts if you don't want the listener to appear
>with an error message.  Then the manual gives an example that shows what
>goes wrong if you don't catch aborts:
>? (defun new-top (&aux form)
>    (setq form (read))
>    (if (eq form 'done)
>        (%set-toplevel #'toplevel-loop)
>        (print (eval form))))
>? (%set-toplevel #'new-top)
>? (toplevel)
>At this point, if you type a command-period, you are supposed to get an
>error
>message saying that it can't throw to tag :abort.
>
>However, when I tried this, and typed a command-period, nothing happened. 
>The new-top function just ignored the command-period.  Is the manual
>correct?  If so, why didn't I get the error message?

The manual is incorrect. There is an abort handler that is always active
that throws to a catch in the kernel which calls the toplevel function.
No error message.

>Can someone give me a simple modification of the above example that catches
>aborts, brings up a message dialog with an error message, and then returns
>to the top-level function?

Time to re-read the Conditions chapter of CLtL2?

(defun new-top ()
  (restart-case
    (new-top-internal)
    (abort ()
           :report (lambda (stream)
                     (format stream 
                             "Pop up message dialog then return to toplevel."))
           (message-dialog "Top-level loop aborted"))))

(defun new-top-internal (&aux form)
  (setq form (read))
  (if (eq form 'done)
    (%set-toplevel #'toplevel-loop)
    (print (eval form))))

(%set-toplevel #'new-top)
(toplevel)