Re: Returning to top-level on error
- From: Pascal Bourguignon <spam@xxxxxxxxxxxxxxxx>
- Date: Thu, 29 Dec 2005 12:15:05 +0100
Nicholas Sandow <njsand@xxxxxxxxxxxxxxxx> writes:
> Can Lisp be told not to enter the "break loop" when encountering an
> error, but instead just return to the top-level?
(ignore-errors (do-something))
> I'm a newbie and I'm typing all kinds of junk into the top-level by
> way of exploration. I don't want Lisp to enter the break loop when I
> type in something nonsensical - I just want it to describe the problem
> and return to top-level.
>
> If this cannot be done in ANSI CL, then a means for doing it in clisp
> would be most helpful.
You can write your own REPL:
(defmacro handling-errors (&body body)
`(HANDLER-CASE (progn ,@body)
(t (ERR) (format t "~&~S~%~A~%" err err))))
(defun repl ()
(do ((hist 1 (1+ hist))
(+eof+ (gensym)))
(nil)
(format t "~%~A[~D]> " (package-name *package*) hist)
(handling-errors
(setf +++ ++ ++ + + - - (read *standard-input* nil +eof+))
(when (or (eq - +eof+)
(member - '((quit)(exit)(continue)) :test (function equal)))
(return-from repl))
(setf /// // // / / (multiple-value-list (eval -)))
(setf *** ** ** * * (first /))
(format t "~& --> ~{~S~^ ;~% ~}~%" /))))
[157]> (repl)
COMMON-LISP-USER[1]> (/ 1 0)
#<SYSTEM::SIMPLE-DIVISION-BY-ZERO #x204D3786>
division by zero
COMMON-LISP-USER[2]>
--
__Pascal Bourguignon__ http://www.informatimago.com/
What is this talk of 'release'? Klingons do not make software 'releases'.
Our software 'escapes' leaving a bloody trail of designers and quality
assurance people in it's wake.
.
- Follow-Ups:
- Re: Returning to top-level on error
- From: Steven M. Haflich
- Re: Returning to top-level on error
- References:
- Returning to top-level on error
- From: Nicholas Sandow
- Returning to top-level on error
- Prev by Date: Re: Python and Lisp Test
- Next by Date: Re: LELISP (-->LISP) --> C/C++ or other common language
- Previous by thread: Returning to top-level on error
- Next by thread: Re: Returning to top-level on error
- Index(es):
Relevant Pages
|
|