diff options
Diffstat (limited to 'doc/lispref/objects.texi')
-rw-r--r-- | doc/lispref/objects.texi | 80 |
1 files changed, 64 insertions, 16 deletions
diff --git a/doc/lispref/objects.texi b/doc/lispref/objects.texi index 111beb5e5b0..aa1e073042f 100644 --- a/doc/lispref/objects.texi +++ b/doc/lispref/objects.texi @@ -60,6 +60,7 @@ to use these types can be found in later chapters. * Type Predicates:: Tests related to types. * Equality Predicates:: Tests of equality between any two objects. * Mutability:: Some objects should not be modified. +* Type Hierarchy:: Type Hierarchy of Emacs Lisp objects. @end menu @node Printed Representation @@ -1180,13 +1181,14 @@ character), Emacs automatically assumes that it is multibyte. You can also use hexadecimal escape sequences (@samp{\x@var{n}}) and octal escape sequences (@samp{\@var{n}}) in string constants. -@strong{But beware:} If a string constant contains hexadecimal or -octal escape sequences, and these escape sequences all specify unibyte -characters (i.e., less than 256), and there are no other literal -non-@acronym{ASCII} characters or Unicode-style escape sequences in -the string, then Emacs automatically assumes that it is a unibyte -string. That is to say, it assumes that all non-@acronym{ASCII} -characters occurring in the string are 8-bit raw bytes. +@strong{But beware:} If a string constant contains octal escape +sequences or one- or two-digit hexadecimal escape sequences, and these +escape sequences all specify unibyte characters (i.e., codepoints less +than 256), and there are no other literal non-@acronym{ASCII} +characters or Unicode-style escape sequences in the string, then Emacs +automatically assumes that it is a unibyte string. That is to say, it +assumes that all non-@acronym{ASCII} characters occurring in the +string are 8-bit raw bytes. In hexadecimal and octal escape sequences, the escaped character code may contain a variable number of digits, so the first subsequent @@ -1373,8 +1375,7 @@ and contents, like this: @example (make-hash-table) - @result{} #s(hash-table size 65 test eql rehash-size 1.5 - rehash-threshold 0.8125 data ()) + @result{} #s(hash-table) @end example @noindent @@ -1484,8 +1485,8 @@ types that are not built into Emacs. @subsection Type Descriptors A @dfn{type descriptor} is a @code{record} which holds information -about a type. Slot 1 in the record must be a symbol naming the type, and -@code{type-of} relies on this to return the type of @code{record} +about a type. The first slot in the record must be a symbol naming the type, +and @code{type-of} relies on this to return the type of @code{record} objects. No other type descriptor slot is used by Emacs; they are free for use by Lisp extensions. @@ -2121,6 +2122,9 @@ with references to further information. @item numberp @xref{Predicates on Numbers, numberp}. +@item obarrayp +@xref{Creating Symbols, obarrayp}. + @item overlayp @xref{Overlays, overlayp}. @@ -2171,7 +2175,7 @@ with references to further information. function @code{type-of}. Recall that each object belongs to one and only one primitive type; @code{type-of} tells you which one (@pxref{Lisp Data Types}). But @code{type-of} knows nothing about non-primitive -types. In most cases, it is more convenient to use type predicates than +types. In most cases, it is preferable to use type predicates than @code{type-of}. @defun type-of object @@ -2181,7 +2185,7 @@ This function returns a symbol naming the primitive type of @code{condition-variable}, @code{cons}, @code{finalizer}, @code{float}, @code{font-entity}, @code{font-object}, @code{font-spec}, @code{frame}, @code{hash-table}, @code{integer}, -@code{marker}, @code{mutex}, @code{overlay}, @code{process}, +@code{marker}, @code{mutex}, @code{obarray}, @code{overlay}, @code{process}, @code{string}, @code{subr}, @code{symbol}, @code{thread}, @code{vector}, @code{window}, or @code{window-configuration}. However, if @var{object} is a record, the type specified by its first @@ -2203,6 +2207,27 @@ slot is returned; @ref{Records}. @end example @end defun +@defun cl-type-of object +This function returns a symbol naming @emph{the} type of +@var{object}. It usually behaves like @code{type-of}, except +that it guarantees to return the most precise type possible, which also +implies that the specific type it returns may change depending on the +Emacs version. For this reason, as a rule you should never compare its +return value against some fixed set of types. + +@example +(cl-type-of 1) + @result{} fixnum +@group +(cl-type-of 'nil) + @result{} null +(cl-type-of (record 'foo)) + @result{} foo +@end group +@end example +@end defun + + @node Equality Predicates @section Equality Predicates @cindex equality @@ -2395,10 +2420,10 @@ The @code{equal} function recursively compares the contents of objects if they are integers, strings, markers, vectors, bool-vectors, byte-code function objects, char-tables, records, or font objects. -If @var{object1} or @var{object2} is a symbol with position, -@code{equal} regards it as its bare symbol when +If @var{object1} or @var{object2} contains symbols with position, +@code{equal} treats them as if they were their bare symbols when @code{symbols-with-pos-enabled} is non-@code{nil}. Otherwise -@code{equal} compares two symbols with position by recursively +@code{equal} compares two symbols with position by comparing their components. @xref{Symbols with Position}. Other objects are considered @code{equal} only if they are @code{eq}. @@ -2493,3 +2518,26 @@ their components. For example, @code{(eq "abc" "abc")} returns literal @code{"abc"}, and returns @code{nil} if it creates two instances. Lisp programs should be written so that they work regardless of whether this optimization is in use. + +@node Type Hierarchy +@section Type Hierarchy of Emacs Lisp Objects + +Lisp object types are organized in a hierarchy, which means that types +can derive from other types. Objects of type B (which derives from type +A) inherit all the characteristics of type A@. This also means that +every object of type B is at the same time an object of type A from +which it derives. + +Every type derives from type @code{t}. + +New types can be defined by the user through @code{defclass} or +@code{cl-defstruct}. + +The Lisp Type Hierarchy for primitive types can be represented as +follows: + +@noindent +@image{elisp_type_hierarchy,,,,.jpg} + +For example type @code{list} derives from (is a special kind of) type +@code{sequence} which itself derives from @code{t}. |