Common Lisp: How to check if something is a type specifier?
Asked Answered
I

2

5

I have been unable to find any built-in method of checking if something is a valid type specifier.

Does such a predicate exist?

(I would make one myself, but alas, the consequences of passing something not a type specifier to typep are undefined. And check-type has no exceptional situations according to the hyperspec.)

Ichthyosaur answered 9/4, 2018 at 2:35 Comment(0)
A
3

You could use Tomohiro Matsuyama's trivial-types system (LLGPL), which among other things defines a wrapper around some implementation-specific predicates:

(defun type-specifier-p (type-specifier)
  "Returns true if TYPE-SPECIFIER is a valid type specfiier."
  (or (documentation type-specifier 'type)
      #+sbcl (sb-ext:valid-type-specifier-p type-specifier)
      #+openmcl (ccl:type-specifier-p type-specifier)
      #+ecl (c::valid-type-specifier type-specifier)))
Andante answered 9/4, 2018 at 8:33 Comment(0)
I
3

To extend the existing answer to support CLISP, use

#+clisp (null (nth-value 1 (ignore-errors (ext:type-expand type-specifier))))

See Type Specifiers.

Immigration answered 9/4, 2018 at 17:12 Comment(1)
I might submit a PR for this, unless you want to do it.Andante

© 2022 - 2024 — McMap. All rights reserved.