home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / lisp / mcl / 1106 < prev    next >
Encoding:
Text File  |  1992-07-31  |  2.1 KB  |  60 lines

  1. Path: sparky!uunet!dtix!darwin.sura.net!mips!sdd.hp.com!uakari.primate.wisc.edu!ames!agate!apple!cambridge.apple.com!bill@cambridge.apple.com
  2. From: bill@cambridge.apple.com (Bill St. Clair)
  3. Newsgroups: comp.lang.lisp.mcl
  4. Subject: Re: toplevel-loop example
  5. Message-ID: <9207311554.AA20428@cambridge.apple.com>
  6. Date: 31 Jul 92 17:36:26 GMT
  7. Sender: info-mcl-request@cambridge.apple.com
  8. Lines: 46
  9. Approved: comp.lang.lisp.mcl@Cambridge.Apple.C0M
  10. Full-Name: Bill St. Clair
  11. Original-To: djskrien@COLBY.EDU (Dale Skrien)
  12. Original-Cc: info-mcl
  13.  
  14. >On page 654 in the MCL 2.0 final manual, I am told that you want your
  15. >toplevel function to catch aborts if you don't want the listener to appear
  16. >with an error message.  Then the manual gives an example that shows what
  17. >goes wrong if you don't catch aborts:
  18. >? (defun new-top (&aux form)
  19. >    (setq form (read))
  20. >    (if (eq form 'done)
  21. >        (%set-toplevel #'toplevel-loop)
  22. >        (print (eval form))))
  23. >? (%set-toplevel #'new-top)
  24. >? (toplevel)
  25. >At this point, if you type a command-period, you are supposed to get an
  26. >error
  27. >message saying that it can't throw to tag :abort.
  28. >
  29. >However, when I tried this, and typed a command-period, nothing happened. 
  30. >The new-top function just ignored the command-period.  Is the manual
  31. >correct?  If so, why didn't I get the error message?
  32.  
  33. The manual is incorrect. There is an abort handler that is always active
  34. that throws to a catch in the kernel which calls the toplevel function.
  35. No error message.
  36.  
  37. >Can someone give me a simple modification of the above example that catches
  38. >aborts, brings up a message dialog with an error message, and then returns
  39. >to the top-level function?
  40.  
  41. Time to re-read the Conditions chapter of CLtL2?
  42.  
  43. (defun new-top ()
  44.   (restart-case
  45.     (new-top-internal)
  46.     (abort ()
  47.            :report (lambda (stream)
  48.                      (format stream 
  49.                              "Pop up message dialog then return to toplevel."))
  50.            (message-dialog "Top-level loop aborted"))))
  51.  
  52. (defun new-top-internal (&aux form)
  53.   (setq form (read))
  54.   (if (eq form 'done)
  55.     (%set-toplevel #'toplevel-loop)
  56.     (print (eval form))))
  57.  
  58. (%set-toplevel #'new-top)
  59. (toplevel)
  60.