Function: cl-typep

cl-typep is an autoloaded and byte-compiled function defined in cl-macs.el.gz.

Signature

(cl-typep VAL TYPE)

Aliases

typep (obsolete since 27.1)

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/cl-macs.el.gz
;;;###autoload
(define-inline cl-typep (val type)
  (inline-letevals (val)
    (pcase (inline-const-val type)
      ((and `(,name . ,args) (guard (get name 'cl-deftype-handler)))
       (inline-quote
        (cl-typep ,val ',(apply (get name 'cl-deftype-handler) args))))
      (`(,(and name (or 'integer 'float 'real 'number))
         . ,(or `(,min ,max) pcase--dontcare))
       (inline-quote
        (and (cl-typep ,val ',name)
             ,(if (memq min '(* nil)) t
                (if (consp min)
                    (inline-quote (> ,val ',(car min)))
                  (inline-quote (>= ,val ',min))))
             ,(if (memq max '(* nil)) t
                (if (consp max)
                    (inline-quote (< ,val ',(car max)))
                  (inline-quote (<= ,val ',max)))))))
      (`(not ,type) (inline-quote (not (cl-typep ,val ',type))))
      (`(,(and name (or 'and 'or)) . ,types)
       (cond
        ((null types) (inline-quote ',(eq name 'and)))
        ((null (cdr types))
         (inline-quote (cl-typep ,val ',(car types))))
        (t
         (let ((head (car types))
               (rest `(,name . ,(cdr types))))
           (cond
            ((eq name 'and)
             (inline-quote (and (cl-typep ,val ',head)
                             (cl-typep ,val ',rest))))
            (t
             (inline-quote (or (cl-typep ,val ',head)
                            (cl-typep ,val ',rest)))))))))
      (`(eql ,v)          (inline-quote (and (eql ,val ',v) t)))
      (`(member . ,args)  (inline-quote (and (memql ,val ',args) t)))
      (`(satisfies ,pred) (inline-quote (funcall #',pred ,val)))
      ((and (pred symbolp) type (guard (get type 'cl-deftype-handler)))
       (inline-quote
        (cl-typep ,val ',(funcall (get type 'cl-deftype-handler)))))
      ((and (pred symbolp) type (guard (get type 'cl-deftype-satisfies)))
       (inline-quote (funcall #',(get type 'cl-deftype-satisfies) ,val)))
      ((and (or 'nil 't) type) (inline-quote ',type))
      ((and (pred symbolp) type)
       (macroexp-warn-and-return
        (format-message "Unknown type: %S" type)
        (let* ((name (symbol-name type))
               (namep (intern (concat name "p"))))
          (cond
           ((cl--macroexp-fboundp namep) (inline-quote (funcall #',namep ,val)))
           ((cl--macroexp-fboundp
             (setq namep (intern (concat name "-p"))))
            (inline-quote (funcall #',namep ,val)))
           ((cl--macroexp-fboundp type) (inline-quote (funcall #',type ,val)))
           (t (error "Unknown type %S" type))))
        nil nil type))
      (type (error "Bad type spec: %S" type)))))