Function: cl-coerce
cl-coerce is an autoloaded and byte-compiled function defined in
cl-extra.el.gz.
Signature
(cl-coerce OBJECT TYPE)
Documentation
Coerce OBJECT to type TYPE.
TYPE is a Common Lisp type specifier.
Aliases
coerce (obsolete since 27.1)
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/cl-extra.el.gz
;;; Type coercion.
;;;###autoload
(defun cl-coerce (x type)
"Coerce OBJECT to type TYPE.
TYPE is a Common Lisp type specifier.
\n(fn OBJECT TYPE)"
(cond ((eq type 'list) (if (listp x) x (append x nil)))
((eq type 'vector) (if (vectorp x) x (vconcat x)))
((eq type 'bool-vector)
(if (bool-vector-p x) x (apply #'bool-vector (cl-coerce x 'list))))
((eq type 'string) (if (stringp x) x (concat x)))
((eq type 'array) (if (arrayp x) x (vconcat x)))
((and (eq type 'character) (stringp x) (= (length x) 1)) (aref x 0))
((and (eq type 'character) (symbolp x))
(cl-coerce (symbol-name x) type))
((eq type 'float) (float x))
((cl-typep x type) x)
(t (error "Can't coerce %s to type %s" x type))))