aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorStefan Monnier2025-05-07 13:24:07 -0400
committerStefan Monnier2025-05-07 13:24:07 -0400
commitb13044dae3db9c449a93f52fecfd848a3e7dd67d (patch)
tree51e3c6c264d6f2d66be41b4323592bc0b3464a8c /doc
parentf6f35644b7f49732fe38fac3c199ef3a6a22abe7 (diff)
downloademacs-b13044dae3db9c449a93f52fecfd848a3e7dd67d.tar.gz
emacs-b13044dae3db9c449a93f52fecfd848a3e7dd67d.zip
cl-types: The big renaming to "derived types"
`cl-defstruct` also defines a type and is also in CL, so "cl-type" is not precise enough to talk about those types defined with `cl-deftype`. Use the term "derived type" to be more clear, as is done in the HyperSpec. * doc/misc/cl.texi (Derived types): Move `cl-deftype` to this new subsection. Document the use of derived types as method specializers. * lisp/emacs-lisp/cl-extra.el (cl--types-of-memo): Rename from `cl--type-unique`. (cl--derived-type-dispatch-list): Rename from `cl--type-dispatch-list`. (cl--derived-type-generalizer): Rename from `cl--type-generalizer`. (cl--derived-type-generalizers): Rename from `cl--type-generalizers`. * lisp/emacs-lisp/cl-lib.el (cl-generic-generalizers) <derived-types>: Rename from <cl-types-of>. Catch but don't hide errors when a derived type cannot be used as an atomic type specifier. * lisp/emacs-lisp/cl-preloaded.el (cl--derived-type-list): Rename from `cl--type-list`. (cl-derived-type-class): Rename from `cl-type-class`. (cl--derived-type-class-make): Rename from `cl--type-class-make`. (cl--define-derived-type): Rename from `cl--type-deftype`.
Diffstat (limited to 'doc')
-rw-r--r--doc/misc/cl.texi28
1 files changed, 26 insertions, 2 deletions
diff --git a/doc/misc/cl.texi b/doc/misc/cl.texi
index 4bceddb8196..a1246b11a8a 100644
--- a/doc/misc/cl.texi
+++ b/doc/misc/cl.texi
@@ -888,8 +888,12 @@ floats. In all other circumstances, @code{cl-coerce} signals an
888error. 888error.
889@end defun 889@end defun
890 890
891@defmac cl-deftype name arglist forms@dots{} 891@node Derived types
892This macro defines a new type called @var{name}. It is similar 892@subsection Derived types
893
894@defmac cl-deftype name arglist [docstring] [decls] forms@dots{}
895This macro defines a new type called @var{name}.
896Types defined this way are called @dfn{derived types}. It is similar
893to @code{defmacro} in many ways; when @var{name} is encountered 897to @code{defmacro} in many ways; when @var{name} is encountered
894as a type name, the body @var{forms} are evaluated and should 898as a type name, the body @var{forms} are evaluated and should
895return a type specifier that is equivalent to the type. The 899return a type specifier that is equivalent to the type. The
@@ -923,6 +927,26 @@ The @code{cl-typecase} (@pxref{Conditionals}) and @code{cl-check-type}
923@code{cl-concatenate}, and @code{cl-merge} functions take type-name 927@code{cl-concatenate}, and @code{cl-merge} functions take type-name
924arguments to specify the type of sequence to return. @xref{Sequences}. 928arguments to specify the type of sequence to return. @xref{Sequences}.
925 929
930Contrary to Common Lisp, CL-Lib supports the use of derived types
931as method specializers. This comes with a significant caveat: derived
932types are much too flexible for Emacs to be able to automatically find
933out which type is a subtype of another, so the ordering of
934methods is not well-defined when several methods are applicable for
935a given argument value and the specializer of one or more of those
936methods is a derived type. To make the order more well-defined, a derived type
937definition can explicitly state that it is a subtype of others using the
938@var{decls} argument:
939
940@example
941(cl-deftype unsigned-byte (&optional bits)
942 (list 'integer 0 (if (eq bits '*) bits (1- (ash 1 bits)))))
943
944(cl-deftype unsigned-8bits ()
945 "Unsigned 8-bits integer."
946 (declare (parents unsigned-byte))
947 '(unsigned-byte 8))
948@end example
949
926@node Equality Predicates 950@node Equality Predicates
927@section Equality Predicates 951@section Equality Predicates
928 952