From: Andreas Thiele
Subject: Analyse/Identify Condition?
Date: 
Message-ID: <f9ccou$e0i$02$1@news.t-online.com>
Hi,

I'd like to react on a single condition. I am interested in the 'wrong 
number of arguments' only. I use a handler-case to catch simple-condition c. 
How do know it is the 'wrong number of arguments'.

(string=
  "~S got ~S arg~:*~P~*, wanted ~:[~;at most ~]~S."
  (simple-condition-format-string c))

works but doesn't look very portable. Isn't there something more elegant?

Any hints?

Andreas

From: Thomas A. Russ
Subject: Re: Analyse/Identify Condition?
Date: 
Message-ID: <ymivebpuc74.fsf@blackcat.isi.edu>
"Andreas Thiele" <······@nospam.com> writes:

> Hi,
> 
> I'd like to react on a single condition. I am interested in the 'wrong 
> number of arguments' only. I use a handler-case to catch simple-condition c. 
> How do know it is the 'wrong number of arguments'.
> 
> (string=
>   "~S got ~S arg~:*~P~*, wanted ~:[~;at most ~]~S."
>   (simple-condition-format-string c))
> 
> works but doesn't look very portable. Isn't there something more elegant?

Unfortunately, this isn't portable and there isn't really any elegant
solution.  That is because this particular type of error isn't one of
the standardized conditions, so it doesn't have a particular type that
you can trap.  In fact, it isn't even always of type SIMPLE-CONDITION.

For example, in Allegro CL the hierarchy of this error is

   PROGRAM-ERROR > ERROR > SERIOUS-CONDITION > CONDITION

so it wouldn't be trapped.  In Macintosh CL the hierarchy is

   SIMPLE-PROGRAM-ERROR > SIMPLE-CONDITION > PROGRAM-ERROR > ERROR >
      SERIOUS-CONDITION > CONDITION

And of course, the format strings vary for all of these.  The best you
could hope to do would be to implement a test for this that was
conditionalized for the implementations you want to support.  Even so,
something as implementation dependent as the format string is liable to
change within an implementation when new versions are released.



-- 
Thomas A. Russ,  USC/Information Sciences Institute
From: Andreas Thiele
Subject: Re: Analyse/Identify Condition?
Date: 
Message-ID: <f9dabg$t5f$00$1@news.t-online.com>
"Thomas A. Russ" <···@sevak.isi.edu> schrieb im Newsbeitrag 
····················@blackcat.isi.edu...
> "Andreas Thiele" <······@nospam.com> writes:
>
>> Hi,
>>
>> I'd like to react on a single condition. I am interested in the 'wrong
>> number of arguments' only. I use a handler-case to catch simple-condition 
>> c.
>> How do know it is the 'wrong number of arguments'.
>>
>> (string=
>>   "~S got ~S arg~:*~P~*, wanted ~:[~;at most ~]~S."
>>   (simple-condition-format-string c))
>>
>> works but doesn't look very portable. Isn't there something more elegant?
>
> Unfortunately, this isn't portable and there isn't really any elegant
> solution.  That is because this particular type of error isn't one of
> the standardized conditions, so it doesn't have a particular type that
> you can trap.  In fact, it isn't even always of type SIMPLE-CONDITION.
>
> For example, in Allegro CL the hierarchy of this error is
>
>   PROGRAM-ERROR > ERROR > SERIOUS-CONDITION > CONDITION
>
> so it wouldn't be trapped.  In Macintosh CL the hierarchy is
>
>   SIMPLE-PROGRAM-ERROR > SIMPLE-CONDITION > PROGRAM-ERROR > ERROR >
>      SERIOUS-CONDITION > CONDITION
>
> And of course, the format strings vary for all of these.  The best you
> could hope to do would be to implement a test for this that was
> conditionalized for the implementations you want to support.  Even so,
> something as implementation dependent as the format string is liable to
> change within an implementation when new versions are released.
> ...

Thanks.

So I am not on the wrong track. Even fancier I get two different kinds of 
condition on the 'wrong number of arguments' error in my implementation 
(Lispworks Windows 5.0.2) depending on the function being compiled or not.

CL-USER 9 > (defun test ())
TEST

CL-USER 10 > (handler-case (funcall 'test 42) (condition (c) (class-name 
(class-of c))))
CONDITIONS:SIMPLE-PROGRAM-ERROR

CL-USER 11 > (compile 'test)
TEST
NIL
NIL

CL-USER 12 > (handler-case (funcall 'test 42) (condition (c) (class-name 
(class-of c))))
CONDITIONS:WRONG-NUM-ARGS-ERROR

I think for my implementation I should find out the 
simple-condition-format-string by triggering the condition on purpose

CL-USER 13 > (handler-case (funcall (lambda ()) 42) (simple-condition (c) 
(simple-condition-format-string c)))
"~S got ~S arg~:*~P~*, wanted ~:[~;at most ~]~S."

and store this string for later use because it might be version dependent.


Andreas

P.S. Meanwhile I found a different solution for my current problem, so I 
actually don't need this condition tracking anymore.