From: Andrew Myers on
I have a situation in which I want to have some restarts active only
for specific kinds of errors, however it seems that when a condition
is thrown via error or signal my :test function in restart-case is
always being passed nil and so cannot determine what kind of error is
being thrown. Code to reproduce this problem is:

(define-condition my-error (error)
((my-message :accessor my-message :initform "my thrown error.")))

(restart-case
(error 'my-error)
(continue (c) :test (lambda (condition) (inspect condition))
(format t "Caught condition of type ~a~%" (type-of c))))

The goal here would be to have the lambda function check the type of
condition to see if the condition being thrown is of type 'my-error'
if it is not then the restart 'continue' should not be available to
upstream handlers. If the condition is of type 'my-error' then the
'continue' restart should be available to handlers upstream. The
problem appears to be that the lambda function and is always being
passed 'nil' which obviously doesn't work for what I want to do.
I'm guessing there's something I don't understand about the restart
system, does anyone have any ideas? I've also tried linking restarts
to specific types with 'with-condition-restarts' but that doesn't seem
to work either.

I'm using allegro common lisp 8.1

Thanks,
Andrew Myers
STScI
From: Joshua Taylor on
On 2010.07.22 1:00 PM, Andrew Myers wrote:
> I have a situation in which I want to have some restarts active only
> for specific kinds of errors, however it seems that when a condition
> is thrown via error or signal my :test function in restart-case is
> always being passed nil and so cannot determine what kind of error is
> being thrown. Code to reproduce this problem is:
>
> (define-condition my-error (error)
> ((my-message :accessor my-message :initform "my thrown error.")))
>
> (restart-case
> (error 'my-error)
> (continue (c) :test (lambda (condition) (inspect condition))
> (format t "Caught condition of type ~a~%" (type-of c))))

Are you sure this illustrates what it's supposed to illustrate? When I
run this (in LispWorks 6.0.1, which I know differs from your setup), it
appears that the test function is called with the condition:

CL-USER 12 >
(define-condition my-error (error)
((my-message :accessor my-message :initform "my thrown error.")))
MY-ERROR

CL-USER 13 >
(restart-case (error 'my-error)
(continue (c) :test (lambda (condition) (inspect condition))
(format t "Caught condition of type ~a~%" (type-of c))))

#<MY-ERROR 23B7496F> is a MY-ERROR
MY-MESSAGE "my thrown error."
REPORTER-FUNCTION CONDITIONS::CONDITION-REPORTER

CL-USER 14 : Inspect 1 >

//JT
From: Andrew Myers on
On Jul 22, 1:27 pm, Joshua Taylor <tay...(a)cs.rpi.edu> wrote:
> On 2010.07.22 1:00 PM, Andrew Myers wrote:
>
> > I have a situation in which I want to have some restarts active only
> > for specific kinds of errors, however it seems that when a condition
> > is thrown via error or signal my :test function in restart-case is
> > always being passed nil and so cannot determine what kind of error is
> > being thrown.  Code to reproduce this problem is:
>
> > (define-condition my-error (error)
> >   ((my-message :accessor my-message :initform "my thrown error.")))
>
> > (restart-case
> >  (error 'my-error)
> >  (continue (c) :test (lambda (condition) (inspect condition))
> >            (format t "Caught condition of type ~a~%" (type-of c))))
>
> Are you sure this illustrates what it's supposed to illustrate?  When I
> run this (in LispWorks 6.0.1, which I know differs from your setup), it
> appears that the test function is called with the condition:
>
> CL-USER 12 >
> (define-condition my-error (error)
>   ((my-message :accessor my-message :initform "my thrown error.")))
> MY-ERROR
>
> CL-USER 13 >
> (restart-case (error 'my-error)
>   (continue (c) :test (lambda (condition) (inspect condition))
>     (format t "Caught condition of type ~a~%" (type-of c))))
>
> #<MY-ERROR 23B7496F> is a MY-ERROR
> MY-MESSAGE             "my thrown error."
> REPORTER-FUNCTION      CONDITIONS::CONDITION-REPORTER
>
> CL-USER 14 : Inspect 1 >
>
> //JT

JT
Thanks for the quick answer, I just installed SBCL on my work machine
and it works there too.
Looks like a problem with Allegro CL and I have an email in to their
support asking about it.
Thanks for the data point!
Andrew
From: Joshua Taylor on
On 2010.07.22 2:00 PM, Andrew Myers wrote:
> On Jul 22, 1:27 pm, Joshua Taylor <tay...(a)cs.rpi.edu> wrote:
>> On 2010.07.22 1:00 PM, Andrew Myers wrote:
>>
>>> I have a situation in which I want to have some restarts active only
>>> for specific kinds of errors, however it seems that when a condition
>>> is thrown via error or signal my :test function in restart-case is
>>> always being passed nil and so cannot determine what kind of error is
>>> being thrown. Code to reproduce this problem is:
>>
>>> (define-condition my-error (error)
>>> ((my-message :accessor my-message :initform "my thrown error.")))
>>
>>> (restart-case
>>> (error 'my-error)
>>> (continue (c) :test (lambda (condition) (inspect condition))
>>> (format t "Caught condition of type ~a~%" (type-of c))))
>>
>> Are you sure this illustrates what it's supposed to illustrate? When I
>> run this (in LispWorks 6.0.1, which I know differs from your setup), it
>> appears that the test function is called with the condition:
>>
>> CL-USER 12 >
>> (define-condition my-error (error)
>> ((my-message :accessor my-message :initform "my thrown error.")))
>> MY-ERROR
>>
>> CL-USER 13 >
>> (restart-case (error 'my-error)
>> (continue (c) :test (lambda (condition) (inspect condition))
>> (format t "Caught condition of type ~a~%" (type-of c))))
>>
>> #<MY-ERROR 23B7496F> is a MY-ERROR
>> MY-MESSAGE "my thrown error."
>> REPORTER-FUNCTION CONDITIONS::CONDITION-REPORTER
>>
>> CL-USER 14 : Inspect 1 >
>>
>> //JT
>
> JT
> Thanks for the quick answer, I just installed SBCL on my work machine
> and it works there too.
> Looks like a problem with Allegro CL and I have an email in to their
> support asking about it.
> Thanks for the data point!
> Andrew

What happens with other test functions? I wonder if something strange
happens particularly with INSPECT. Also, what happens if the
restartable-form is some other function call or something other than
(error 'my-error). With (error 'my-error), the restarts are explicitly
associated with the condition. I wonder if something might be happening
there too.

"If the restartable-form is a list whose car is any of the symbols
signal, error, cerror, or warn (or is a macro form which macroexpands
into such a list), then with-condition-restarts is used implicitly to
associate the indicated restarts with the condition to be signaled."
http://www.lispworks.com/documentation/HyperSpec/Body/m_rst_ca.htm

//JT
From: Madhu on

* Andrew Myers Wrote on Thu, 22 Jul 2010 11:00:54 -0700 (PDT):
| Thanks for the quick answer, I just installed SBCL on my work machine
| and it works there too. Looks like a problem with Allegro CL and I
| have an email in to their support asking about it. Thanks for the
| data point! Andrew

The issue is not so clear, given your intent.

See the thread starting at
<http://news.gmane.org/group/gmane.lisp.openmcl.devel/thread=5944/>

And my suggestion there
--
Madhu