Lisp HUG Maillist Archive

Testing for a type specifier

How can I check that something is a valid type specifier ?

Namely, I want to extend typep use and I need to know if
the second argument is a type specifier or not.

I notice that sbcl has a sb-ext:valid-type-specifier-p. 
Does LW has something like that (even undocumented) ?
Or is there a specific trick to do that ?

I can use typep and put a handler-case on illegal-type-specifier
but is there any performance penalty in doing so ?

Thanks for your advice,

-- 
Fabrice

Re: Testing for a type specifier

Hi,

The consequences are undefined if you pass something that is not a type as a second parameter to typep, so wrapping typep with some exception handler is not good enough.

subtypep is specified not to have any exceptional situations, so it should be safe to use for determining whether something is a type, considering that (subtype something 't) is always true. The following should be a reasonable portable definition:

(defun valid-type-specifier-p (thing)
  (ignore-errors (subtypep thing 't)))


Pascal

On 17 Mar 2012, at 16:01, Fabrice Popineau wrote:

> How can I check that something is a valid type specifier ?
> 
> Namely, I want to extend typep use and I need to know if
> the second argument is a type specifier or not.
> 
> I notice that sbcl has a sb-ext:valid-type-specifier-p. 
> Does LW has something like that (even undocumented) ?
> Or is there a specific trick to do that ?
> 
> I can use typep and put a handler-case on illegal-type-specifier
> but is there any performance penalty in doing so ?
> 
> Thanks for your advice,
> 
> -- 
> Fabrice
> 

--
Pascal Costanza




Updated at: 2020-12-10 08:36 UTC