Re: Returning to top-level on error



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.
.



Relevant Pages

  • Returning to top-level on error
    ... 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 ...
    (comp.lang.lisp)
  • Re: Returning to top-level on error
    ... 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 ...
    (comp.lang.lisp)
  • Re: profiling in PCL book
    ... called the read-eval-print loop, or REPL for short. ... to as the top-level, the top-level listener, or the Lisp listener" ...
    (comp.lang.lisp)