Function: cl--define-derived-type

cl--define-derived-type is a byte-compiled function defined in cl-preloaded.el.gz.

Signature

(cl--define-derived-type NAME EXPANDER PREDICATE &optional PARENTS)

Documentation

Register derived type with NAME for method dispatching.

EXPANDER is the function that computes the type specifier from the arguments passed to the derived type. PREDICATE is the precomputed function to test this type when used as an atomic type, or nil if it cannot be used as an atomic type. PARENTS is a list of types NAME is a subtype of, or nil.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/cl-preloaded.el.gz
(defun cl--define-derived-type (name expander predicate &optional parents)
  "Register derived type with NAME for method dispatching.
EXPANDER is the function that computes the type specifier from
the arguments passed to the derived type.
PREDICATE is the precomputed function to test this type when used as an
atomic type, or nil if it cannot be used as an atomic type.
PARENTS is a list of types NAME is a subtype of, or nil."
  (let* ((class (cl--find-class name)))
    (when class
      (or (cl-derived-type-class-p class)
          ;; FIXME: We have some uses `cl-deftype' in Emacs that
          ;; "complement" another declaration of the same type,
          ;; so maybe we should turn this into a warning (and
          ;; not overwrite the `cl--find-class' in that case)?
          (error "Type %S already in another class: %S" name (type-of class))))
    ;; Setup a type descriptor for NAME.
    (setf (cl--find-class name)
          (cl--derived-type-class-make
           name
           (and (fboundp 'function-documentation) ;Bootstrap corner case.
                (function-documentation expander))
           parents))
    (define-symbol-prop name 'cl-deftype-handler expander)
    (when predicate
      (define-symbol-prop name 'cl-deftype-satisfies predicate))))