From: verec
Subject: trapping REPL "conditions"
Date: 
Message-ID: <46d8a97e$0$642$5a6aecb4@news.aaisp.net.uk>
Is there anyway to define a (preferably portable) function
that kind of "intercepts" conditions as "thrown" from the REPL
and always "selects" the abort/return to top level clause?

Something like:

(defun trap-repl-condition (onOff)
  ( ...))

used as:

CL-USER> (trap-repl-condition t)
CL-USER> (+ a 9)
Error: The variable a is unbound.
CL-USER> (+ 3 3)
6
CL-USER> (trap-repl-condition nil)
CL-USER> (+ a 9)
Error: The variable a is unbound.
  1 (continue) Try evaluating a again.
  2 Return the value of :a instead.
  3 Specify a value to use this time instead of evaluating a.
  4 Specify a value to set a to.
  5 (abort) Return to level 0.
  6 Return to top loop level 0.

Type :b for backtrace, :c <option number> to proceed,  or :? for other options

CL-USER : 1 > :c 5
CL-USER>

I have read about the IGNORE-ERRORS macro, as well as
http://www.nhplace.com/kent/Papers/Revision-18.txt.
I have also read the entry on *BREAK-ON-SIGNALS* but
I don't understdand how it could help,

CL-USER> (ignore-errors (/ a 9))
nil
#<unbound-variable 21A196EF>
CL-USER>

But going from

(ignore-errors (code-that-I-want-to-test args))

to simply:

(code-that-I-want-to-test args)

still eludes me.

I'd find this a time saving device when experimenting, not
having to visually scan all the available restarts to spot the
one that says "abort": when typing in many short unrelated
functions and testing them, it is just irritating to have to
go through this, when "abort, please, let me correct my typos"
is all I want really.

Any idea where/how to start?

Many thanks
--
JFB

From: Carl Taylor
Subject: Re: trapping REPL "conditions"
Date: 
Message-ID: <zA2Ci.479435$p47.136849@bgtnsc04-news.ops.worldnet.att.net>
"verec" <·····@mac.com> wrote in message 
····························@news.aaisp.net.uk...
> Is there anyway to define a (preferably portable) function
> that kind of "intercepts" conditions as "thrown" from the REPL
> and always "selects" the abort/return to top level clause?

*debugger-hook* is what you want.

Carl Taylor



CL-USER 1 >
(defun alternative-debugger-hook (condition hook)
  (declare (ignore hook))
  (when (find-restart 'abort condition)
    (format t "~%~A~2%" condition)
    (abort condition)))
ALTERNATIVE-DEBUGGER-HOOK

CL-USER 2 >
(compile *)
ALTERNATIVE-DEBUGGER-HOOK
NIL
NIL

CL-USER 3 > (setf *debugger-hook* #'alternative-debugger-hook)
#<Function ALTERNATIVE-DEBUGGER-HOOK 2170908A>

CL-USER 4 > (/ 12345 0)

Division-by-zero caused by / of (12345 0).
From: verec
Subject: Re: trapping REPL "conditions"
Date: 
Message-ID: <46d8c273$0$645$5a6aecb4@news.aaisp.net.uk>
On 2007-09-01 01:43:11 +0100, "Carl Taylor" <··········@att.net> said:
> "verec" <·····@mac.com> wrote in message 
> ····························@news.aaisp.net.uk...
>> Is there anyway to define a (preferably portable) function
>> that kind of "intercepts" conditions as "thrown" from the REPL
>> and always "selects" the abort/return to top level clause?
> 
> CL-USER 1 >
> (defun alternative-debugger-hook (condition hook)
>   (declare (ignore hook))
>   (when (find-restart 'abort condition)
>     (format t "~%~A~2%" condition)
>     (abort condition)))
> ALTERNATIVE-DEBUGGER-HOOK
> 
> CL-USER 2 >
> (compile *)
> ALTERNATIVE-DEBUGGER-HOOK
> NIL
> NIL
> 
> CL-USER 3 > (setf *debugger-hook* #'alternative-debugger-hook)
> #<Function ALTERNATIVE-DEBUGGER-HOOK 2170908A>
> 
> CL-USER 4 > (/ 12345 0)
> 
> Division-by-zero caused by / of (12345 0).

Excellent! Thanks a lot.

All packaged up:

(defun alternative-debugger-hook (condition hook)
  (declare (ignore hook))
  (when (find-restart 'abort condition)
    (format t "~%~A~2%" condition)
    (abort condition)))

(defun trap-repl-condition (on-off)
  (if on-off
      (setf *debugger-hook* #'alternative-debugger-hook)
    (setf *debugger-hook* nil)))

Then:

CL-USER> (trap-repl-condition nil)
nil

CL-USER> (/ a 9)

Error: The variable a is unbound.
  1 (continue) Try evaluating a again.
  2 Return the value of :a instead.
  3 Specify a value to use this time instead of evaluating a.
  4 Specify a value to set a to.
  5 (abort) Return to level 0.
  6 Return to top loop level 0.

Type :b for backtrace, :c <option number> to proceed,  or :? for other options

CL-USER: 1 > :c 5

CL-USER> (trap-repl-condition t)
#<Function alternative-debugger-hook 200F70D2>

CL-USER> (/ a 9)

The variable a is unbound.

CL-USER>

Thanks again.
--
JFB
From: Mike G.
Subject: Re: trapping REPL "conditions"
Date: 
Message-ID: <1188764424.916446.254990@d55g2000hsg.googlegroups.com>
On Aug 31, 9:37 pm, verec <·····@mac.com> wrote:
> On 2007-09-01 01:43:11 +0100, "Carl Taylor" <··········@att.net> said:
>
>
>
> > "verec" <·····@mac.com> wrote in message
> >····························@news.aaisp.net.uk...
> >> Is there anyway to define a (preferably portable) function
> >> that kind of "intercepts" conditions as "thrown" from the REPL
> >> and always "selects" the abort/return to top level clause?
>
> > CL-USER 1 >
> > (defun alternative-debugger-hook (condition hook)
> >   (declare (ignore hook))
> >   (when (find-restart 'abort condition)
> >     (format t "~%~A~2%" condition)
> >     (abort condition)))
> > ALTERNATIVE-DEBUGGER-HOOK
>
> > CL-USER 2 >
> > (compile *)
> > ALTERNATIVE-DEBUGGER-HOOK
> > NIL
> > NIL
>
> > CL-USER 3 > (setf *debugger-hook* #'alternative-debugger-hook)
> > #<Function ALTERNATIVE-DEBUGGER-HOOK 2170908A>
>
> > CL-USER 4 > (/ 12345 0)
>
> > Division-by-zero caused by / of (12345 0).
>
> Excellent! Thanks a lot.
>
> All packaged up:
>
> (defun alternative-debugger-hook (condition hook)
>   (declare (ignore hook))
>   (when (find-restart 'abort condition)
>     (format t "~%~A~2%" condition)
>     (abort condition)))
>
> (defun trap-repl-condition (on-off)
>   (if on-off
>       (setf *debugger-hook* #'alternative-debugger-hook)
>     (setf *debugger-hook* nil)))
>
> Then:
>
> CL-USER> (trap-repl-condition nil)
> nil
>
> CL-USER> (/ a 9)
>
> Error: The variable a is unbound.
>   1 (continue) Try evaluating a again.
>   2 Return the value of :a instead.
>   3 Specify a value to use this time instead of evaluating a.
>   4 Specify a value to set a to.
>   5 (abort) Return to level 0.
>   6 Return to top loop level 0.
>
> Type :b for backtrace, :c <option number> to proceed,  or :? for other options
>
> CL-USER: 1 > :c 5
>
> CL-USER> (trap-repl-condition t)
> #<Function alternative-debugger-hook 200F70D2>
>
> CL-USER> (/ a 9)
>
> The variable a is unbound.
>
> CL-USER>
>
> Thanks again.
> --
> JFB

This works. I do it quite often. One thing to watch out for: SLIME's
integrated debugger raises the condition regardless. I haven't found
out how to turn that off in SLIME.