@c -*-texinfo-*-
@c This is part of the GNU Emacs Lisp Reference Manual.
-@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998 Free Software Foundation, Inc.
+@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2003
+@c Free Software Foundation, Inc.
@c See the file elisp.texi for copying conditions.
@setfilename ../info/objects
@node Lisp Data Types, Numbers, Introduction, Top
@cindex primitive type
A few fundamental object types are built into Emacs. These, from
-which all other types are constructed, are called @dfn{primitive
-types}. Each object belongs to one and only one primitive type. These
-types include @dfn{integer}, @dfn{float}, @dfn{cons}, @dfn{symbol},
-@dfn{string}, @dfn{vector}, @dfn{subr}, @dfn{byte-code function}, and
-several special types, such as @dfn{buffer}, that are related to
-editing. (@xref{Editing Types}.)
+which all other types are constructed, are called @dfn{primitive types}.
+Each object belongs to one and only one primitive type. These types
+include @dfn{integer}, @dfn{float}, @dfn{cons}, @dfn{symbol},
+@dfn{string}, @dfn{vector}, @dfn{hash-table}, @dfn{subr}, and
+@dfn{byte-code function}, plus several special types, such as
+@dfn{buffer}, that are related to editing. (@xref{Editing Types}.)
Each primitive type has a corresponding Lisp function that checks
whether an object is a member of that type.
* Comments:: Comments and their formatting conventions.
* Programming Types:: Types found in all Lisp systems.
* Editing Types:: Types specific to Emacs.
+* Circular Objects:: Read syntax for circular structure.
* Type Predicates:: Tests related to types.
* Equality Predicates:: Tests of equality between any two objects.
@end menu
object. @xref{Read and Print}.
Most objects have more than one possible read syntax. Some types of
-object have no read syntax; except for these cases, the printed
-representation of an object is also a read syntax for it.
+object have no read syntax, since it may not make sense to enter objects
+of these types directly in a Lisp program. Except for these cases, the
+printed representation of an object is also a read syntax for it.
In other languages, an expression is text; it has no other form. In
Lisp, an expression is primarily a Lisp object and only secondarily the
@cindex hash notation
Every type has a printed representation. Some types have no read
-syntax, since it may not make sense to enter objects of these types
-directly in a Lisp program. For example, the buffer type does not have
-a read syntax. Objects of these types are printed in @dfn{hash
-notation}: the characters @samp{#<} followed by a descriptive string
-(typically the type name followed by the name of the object), and closed
-with a matching @samp{>}. Hash notation cannot be read at all, so the
-Lisp reader signals the error @code{invalid-read-syntax} whenever it
-encounters @samp{#<}.
+syntax---for example, the buffer type has none. Objects of these types
+are printed in @dfn{hash notation}: the characters @samp{#<} followed by
+a descriptive string (typically the type name followed by the name of
+the object), and closed with a matching @samp{>}. Hash notation cannot
+be read at all, so the Lisp reader signals the error
+@code{invalid-read-syntax} whenever it encounters @samp{#<}.
@kindex invalid-read-syntax
@example
* Vector Type:: One-dimensional arrays.
* Char-Table Type:: One-dimensional sparse arrays indexed by characters.
* Bool-Vector Type:: One-dimensional arrays of @code{t} or @code{nil}.
+* Hash Table Type:: Super-fast lookup tables.
* Function Type:: A piece of executable code you can call from elsewhere.
* Macro Type:: A method of expanding an expression into another
expression, more fundamental but less pretty.
The range of values for integers in Emacs Lisp is @minus{}134217728 to
134217727 (28 bits; i.e.,
-@ifinfo
+@ifnottex
-2**27
-@end ifinfo
+@end ifnottex
@tex
-$-2^{27}$
+@math{-2^{27}}
@end tex
to
-@ifinfo
+@ifnottex
2**27 - 1)
-@end ifinfo
+@end ifnottex
@tex
-$2^{28}-1$)
+@math{2^{28}-1})
@end tex
on most machines. (Some machines may provide a wider range.) It is
important to note that the Emacs Lisp arithmetic functions do not check
@group
-1 ; @r{The integer -1.}
1 ; @r{The integer 1.}
-1. ; @r{Also The integer 1.}
+1. ; @r{Also the integer 1.}
+1 ; @r{Also the integer 1.}
-268435457 ; @r{Also the integer 1!}
- ; @r{ (on a 28-bit implementation)}
+268435457 ; @r{Also the integer 1 on a 28-bit implementation.}
@end group
@end example
@node Floating Point Type
@subsection Floating Point Type
- Emacs supports floating point numbers (though there is a compilation
-option to disable them). The precise range of floating point numbers is
-machine-specific.
+ Floating point numbers are the computer equivalent of scientific
+notation. The precise number of significant figures and the range of
+possible exponents is machine-specific; Emacs always uses the C data
+type @code{double} to store the value.
The printed representation for floating point numbers requires either
a decimal point (with at least one digit following), an exponent, or
@node Character Type
@subsection Character Type
-@cindex @sc{ASCII} character codes
+@cindex @sc{ascii} character codes
A @dfn{character} in Emacs Lisp is nothing more than an integer. In
other words, characters are represented by their character codes. For
Characters in strings, buffers, and files are currently limited to the
range of 0 to 524287---nineteen bits. But not all values in that range
-are valid character codes. Characters that represent keyboard input
-have a much wider range, so they can modifier keys such as Control, Meta
-and Shift.
+are valid character codes. Codes 0 through 127 are @sc{ascii} codes; the
+rest are non-@sc{ascii} (@pxref{Non-ASCII Characters}). Characters that represent
+keyboard input have a much wider range, to encode modifier keys such as
+Control, Meta and Shift.
@cindex read syntax for characters
@cindex printed representation for characters
@cindex syntax for characters
+@cindex @samp{?} in character constant
+@cindex question mark in character constant
Since characters are really integers, the printed representation of a
character is a decimal number. This is also a possible read syntax for
a character, but writing characters that way in Lisp programs is a very
The usual read syntax for alphanumeric characters is a question mark
followed by the character; thus, @samp{?A} for the character
@kbd{A}, @samp{?B} for the character @kbd{B}, and @samp{?a} for the
-character @kbd{a}.
+character @kbd{a}.
For example:
You can use the same syntax for punctuation characters, but it is
often a good idea to add a @samp{\} so that the Emacs commands for
-editing Lisp code don't get confused. For example, @samp{?\ } is the
-way to write the space character. If the character is @samp{\}, you
-@emph{must} use a second @samp{\} to quote it: @samp{?\\}.
+editing Lisp code don't get confused. For example, @samp{?\(} is the
+way to write the open-paren character. If the character is @samp{\},
+you @emph{must} use a second @samp{\} to quote it: @samp{?\\}.
@cindex whitespace
@cindex bell character
@cindex @samp{\r}
@cindex escape
@cindex @samp{\e}
- You can express the characters Control-g, backspace, tab, newline,
-vertical tab, formfeed, return, and escape as @samp{?\a}, @samp{?\b},
-@samp{?\t}, @samp{?\n}, @samp{?\v}, @samp{?\f}, @samp{?\r}, @samp{?\e},
-respectively. Thus,
+@cindex space
+@cindex @samp{\s}
+ You can express the characters control-g, backspace, tab, newline,
+vertical tab, formfeed, space, return, del, and escape as @samp{?\a},
+@samp{?\b}, @samp{?\t}, @samp{?\n}, @samp{?\v}, @samp{?\f},
+@samp{?\s}, @samp{?\r}, @samp{?\d}, and @samp{?\e}, respectively.
+Thus,
@example
-?\a @result{} 7 ; @r{@kbd{C-g}}
+?\a @result{} 7 ; @r{control-g, @kbd{C-g}}
?\b @result{} 8 ; @r{backspace, @key{BS}, @kbd{C-h}}
?\t @result{} 9 ; @r{tab, @key{TAB}, @kbd{C-i}}
-?\n @result{} 10 ; @r{newline, @key{LFD}, @kbd{C-j}}
+?\n @result{} 10 ; @r{newline, @kbd{C-j}}
?\v @result{} 11 ; @r{vertical tab, @kbd{C-k}}
?\f @result{} 12 ; @r{formfeed character, @kbd{C-l}}
?\r @result{} 13 ; @r{carriage return, @key{RET}, @kbd{C-m}}
?\e @result{} 27 ; @r{escape character, @key{ESC}, @kbd{C-[}}
+?\s @result{} 32 ; @r{space character, @key{SPC}}
?\\ @result{} 92 ; @r{backslash character, @kbd{\}}
+?\d @result{} 127 ; @r{delete character, @key{DEL}}
@end example
@cindex escape sequence
These sequences which start with backslash are also known as
-@dfn{escape sequences}, because backslash plays the role of an escape
-character; this usage has nothing to do with the character @key{ESC}.
+@dfn{escape sequences}, because backslash plays the role of an
+``escape character''; this terminology has nothing to do with the
+character @key{ESC}. @samp{\s} is meant for use only in character
+constants; in string constants, just write the space.
@cindex control characters
Control characters may be represented using yet another read syntax.
@end example
In strings and buffers, the only control characters allowed are those
-that exist in @sc{ASCII}; but for keyboard input purposes, you can turn
+that exist in @sc{ascii}; but for keyboard input purposes, you can turn
any character into a control character with @samp{C-}. The character
-codes for these non-@sc{ASCII} control characters include the
-@iftex
-$2^{26}$
-@end iftex
-@ifinfo
+codes for these non-@sc{ascii} control characters include the
+@tex
+@math{2^{26}}
+@end tex
+@ifnottex
2**26
-@end ifinfo
+@end ifnottex
bit as well as the code for the corresponding non-control
-character. Ordinary terminals have no way of generating non-@sc{ASCII}
-control characters, but you can generate them straightforwardly using an
-X terminal.
+character. Ordinary terminals have no way of generating non-@sc{ascii}
+control characters, but you can generate them straightforwardly using X
+and other window systems.
For historical reasons, Emacs treats the @key{DEL} character as
the control equivalent of @kbd{?}:
@noindent
As a result, it is currently not possible to represent the character
-@kbd{Control-?}, which is a meaningful input character under X. It is
-not easy to change this as various Lisp files refer to @key{DEL} in this
-way.
+@kbd{Control-?}, which is a meaningful input character under X, using
+@samp{\C-}. It is not easy to change this, as various Lisp files refer
+to @key{DEL} in this way.
For representing control characters to be found in files or strings,
we recommend the @samp{^} syntax; for control characters in keyboard
-input, we prefer the @samp{C-} syntax. This does not affect the meaning
-of the program, but may guide the understanding of people who read it.
+input, we prefer the @samp{C-} syntax. Which one you use does not
+affect the meaning of the program, but may guide the understanding of
+people who read it.
@cindex meta characters
A @dfn{meta character} is a character typed with the @key{META}
modifier key. The integer that represents such a character has the
-@iftex
-$2^{27}$
-@end iftex
-@ifinfo
+@tex
+@math{2^{27}}
+@end tex
+@ifnottex
2**27
-@end ifinfo
+@end ifnottex
bit set (which on most machines makes it a negative number). We
use high bits for this and other modifiers to make possible a wide range
of basic character codes.
In a string, the
-@iftex
-$2^{7}$
-@end iftex
-@ifinfo
+@tex
+@math{2^{7}}
+@end tex
+@ifnottex
2**7
-@end ifinfo
-bit attached to an ASCII character indicates a meta character; thus, the
+@end ifnottex
+bit attached to an @sc{ascii} character indicates a meta character; thus, the
meta characters that can fit in a string have codes in the range from
-128 to 255, and are the meta versions of the ordinary @sc{ASCII}
+128 to 255, and are the meta versions of the ordinary @sc{ascii}
characters. (In Emacs versions 18 and older, this convention was used
for characters outside of strings as well.)
@samp{?\M-\C-b}, @samp{?\C-\M-b}, or @samp{?\M-\002}.
The case of a graphic character is indicated by its character code;
-for example, @sc{ASCII} distinguishes between the characters @samp{a}
-and @samp{A}. But @sc{ASCII} has no way to represent whether a control
+for example, @sc{ascii} distinguishes between the characters @samp{a}
+and @samp{A}. But @sc{ascii} has no way to represent whether a control
character is upper case or lower case. Emacs uses the
-@iftex
-$2^{25}$
-@end iftex
-@ifinfo
+@tex
+@math{2^{25}}
+@end tex
+@ifnottex
2**25
-@end ifinfo
-bit to indicate that the shift key was used for typing a control
+@end ifnottex
+bit to indicate that the shift key was used in typing a control
character. This distinction is possible only when you use X terminals
-or other special terminals; ordinary terminals do not indicate the
-distinction to the computer in any way.
+or other special terminals; ordinary terminals do not report the
+distinction to the computer in any way. The Lisp syntax for
+the shift bit is @samp{\S-}; thus, @samp{?\C-\S-o} or @samp{?\C-\S-O}
+represents the shifted-control-o character.
@cindex hyper characters
@cindex super characters
@cindex alt characters
- The X Window System defines three other modifier bits that can be set
+ The X Window System defines three other @anchor{modifier bits}
+modifier bits that can be set
in a character: @dfn{hyper}, @dfn{super} and @dfn{alt}. The syntaxes
-for these bits are @samp{\H-}, @samp{\s-} and @samp{\A-}. Thus,
-@samp{?\H-\M-\A-x} represents @kbd{Alt-Hyper-Meta-x}.
-@iftex
+for these bits are @samp{\H-}, @samp{\s-} and @samp{\A-}. (Case is
+significant in these prefixes.) Thus, @samp{?\H-\M-\A-x} represents
+@kbd{Alt-Hyper-Meta-x}. (Note that @samp{\s} with no following @samp{-}
+represents the space character.)
+@tex
Numerically, the
-bit values are $2^{22}$ for alt, $2^{23}$ for super and $2^{24}$ for hyper.
-@end iftex
-@ifinfo
+bit values are @math{2^{22}} for alt, @math{2^{23}} for super and @math{2^{24}} for hyper.
+@end tex
+@ifnottex
Numerically, the
bit values are 2**22 for alt, 2**23 for super and 2**24 for hyper.
-@end ifinfo
+@end ifnottex
-@cindex @samp{?} in character constant
-@cindex question mark in character constant
@cindex @samp{\} in character constant
@cindex backslash in character constant
@cindex octal character code
mark followed by a backslash and the octal character code (up to three
octal digits); thus, @samp{?\101} for the character @kbd{A},
@samp{?\001} for the character @kbd{C-a}, and @code{?\002} for the
-character @kbd{C-b}. Although this syntax can represent any @sc{ASCII}
+character @kbd{C-b}. Although this syntax can represent any @sc{ascii}
character, it is preferred only when the precise octal value is more
-important than the @sc{ASCII} representation.
+important than the @sc{ascii} representation.
@example
@group
and the hexadecimal character code. You can use any number of hex
digits, so you can represent any character code in this way.
Thus, @samp{?\x41} for the character @kbd{A}, @samp{?\x1} for the
-character @kbd{C-a}, and @code{?\x8c0} for the character
+character @kbd{C-a}, and @code{?\x8e0} for the Latin-1 character
@iftex
-@`a.
+@samp{@`a}.
@end iftex
-@ifinfo
+@ifnottex
@samp{a} with grave accent.
-@end ifinfo
+@end ifnottex
A backslash is allowed, and harmless, preceding any character without
a special escape meaning; thus, @samp{?\+} is equivalent to @samp{?+}.
There is no reason to add a backslash before most characters. However,
you should add a backslash before any of the characters
@samp{()\|;'`"#.,} to avoid confusing the Emacs commands for editing
-Lisp code. Also add a backslash before whitespace characters such as
+Lisp code. You can also add a backslash before whitespace characters such as
space, tab, newline and formfeed. However, it is cleaner to use one of
-the easily readable escape sequences, such as @samp{\t}, instead of an
-actual whitespace character such as a tab.
+the easily readable escape sequences, such as @samp{\t} or @samp{\s},
+instead of an actual whitespace character such as a tab or a space.
+(If you do write backslash followed by a space, you should write
+an extra space after the character constant to separate it from the
+following text.)
@node Symbol Type
@subsection Symbol Type
intended. But you can use one symbol in all of these ways,
independently.
+ A symbol whose name starts with a colon (@samp{:}) is called a
+@dfn{keyword symbol}. These symbols automatically act as constants, and
+are normally used only by comparing an unknown symbol with a few
+specific alternatives.
+
@cindex @samp{\} in symbols
@cindex backslash in symbols
A symbol name can contain any characters whatever. Most symbol names
@samp{-+=*/}. Such names require no special punctuation; the characters
of the name suffice as long as the name does not look like a number.
(If it does, write a @samp{\} at the beginning of the name to force
-interpretation as a symbol.) The characters @samp{_~!@@$%^&:<>@{@}} are
+interpretation as a symbol.) The characters @samp{_~!@@$%^&:<>@{@}?} are
less often used but also require no special punctuation. Any other
characters may be included in a symbol's name by escaping them with a
backslash. In contrast to its use in strings, however, a backslash in
the name of a symbol simply quotes the single character that follows the
backslash. For example, in a string, @samp{\t} represents a tab
character; in the name of a symbol, however, @samp{\t} merely quotes the
-letter @kbd{t}. To have a symbol with a tab character in its name, you
+letter @samp{t}. To have a symbol with a tab character in its name, you
must actually use a tab (preceded with a backslash). But it's rare to
do such a thing.
Here are several examples of symbol names. Note that the @samp{+} in
the fifth example is escaped to prevent it from being read as a number.
-This is not necessary in the sixth example because the rest of the name
+This is not necessary in the seventh example because the rest of the name
makes it invalid as a number.
@example
@end group
@end example
+@ifinfo
+@c This uses ``colon'' instead of a literal `:' because Info cannot
+@c cope with a `:' in a menu
+@cindex @samp{#@var{colon}} read syntax
+@end ifinfo
+@ifnotinfo
+@cindex @samp{#:} read syntax
+@end ifnotinfo
+ Normally the Lisp reader interns all symbols (@pxref{Creating
+Symbols}). To prevent interning, you can write @samp{#:} before the
+name of the symbol.
+
@node Sequence Type
@subsection Sequence Types
arrays. Thus, an object of type list or of type array is also
considered a sequence.
- Arrays are further subdivided into strings and vectors. Vectors can
-hold elements of any type, but string elements must be characters in the
-range from 0 to 255. However, the characters in a string can have text
-properties like characters in a buffer (@pxref{Text Properties});
-vectors do not support text properties even when their elements happen
-to be characters.
-
- Lists, strings and vectors are different, but they have important
-similarities. For example, all have a length @var{l}, and all have
-elements which can be indexed from zero to @var{l} minus one. Also,
-several functions, called sequence functions, accept any kind of
+ Arrays are further subdivided into strings, vectors, char-tables and
+bool-vectors. Vectors can hold elements of any type, but string
+elements must be characters, and bool-vector elements must be @code{t}
+or @code{nil}. Char-tables are like vectors except that they are
+indexed by any valid character code. The characters in a string can
+have text properties like characters in a buffer (@pxref{Text
+Properties}), but vectors do not support text properties, even when
+their elements happen to be characters.
+
+ Lists, strings and the other array types are different, but they have
+important similarities. For example, all have a length @var{l}, and all
+have elements which can be indexed from zero to @var{l} minus one.
+Several functions, called sequence functions, accept any kind of
sequence. For example, the function @code{elt} can be used to extract
an element of a sequence, given its index. @xref{Sequences Arrays
Vectors}.
- It is impossible to read the same sequence twice, since sequences are
-always created anew upon reading. If you read the read syntax for a
-sequence twice, you get two sequences with equal contents. There is one
-exception: the empty list @code{()} always stands for the same object,
-@code{nil}.
+ It is generally impossible to read the same sequence twice, since
+sequences are always created anew upon reading. If you read the read
+syntax for a sequence twice, you get two sequences with equal contents.
+There is one exception: the empty list @code{()} always stands for the
+same object, @code{nil}.
@node Cons Cell Type
@subsection Cons Cell and List Types
@cindex address field of register
@cindex decrement field of register
+@cindex pointers
+
+ A @dfn{cons cell} is an object that consists of two slots, called the
+@sc{car} slot and the @sc{cdr} slot. Each slot can @dfn{hold} or
+@dfn{refer to} any Lisp object. We also say that ``the @sc{car} of
+this cons cell is'' whatever object its @sc{car} slot currently holds,
+and likewise for the @sc{cdr}.
- A @dfn{cons cell} is an object comprising two pointers named the
-@sc{car} and the @sc{cdr}. Each of them can point to any Lisp object.
+@quotation
+A note to C programmers: in Lisp, we do not distinguish between
+``holding'' a value and ``pointing to'' the value, because pointers in
+Lisp are implicit.
+@end quotation
A @dfn{list} is a series of cons cells, linked together so that the
-@sc{cdr} of each cons cell points either to another cons cell or to the
+@sc{cdr} slot of each cons cell holds either the next cons cell or the
empty list. @xref{Lists}, for functions that work on lists. Because
most cons cells are used as part of lists, the phrase @dfn{list
structure} has come to refer to any structure made out of cons cells.
- The names @sc{car} and @sc{cdr} have only historical meaning now. The
+ The names @sc{car} and @sc{cdr} derive from the history of Lisp. The
original Lisp implementation ran on an @w{IBM 704} computer which
divided words into two parts, called the ``address'' part and the
``decrement''; @sc{car} was an instruction to extract the contents of
the address part of a register, and @sc{cdr} an instruction to extract
the contents of the decrement. By contrast, ``cons cells'' are named
-for the function @code{cons} that creates them, which in turn is named
+for the function @code{cons} that creates them, which in turn was named
for its purpose, the construction of cells.
@cindex atom
Upon reading, each object inside the parentheses becomes an element
of the list. That is, a cons cell is made for each element. The
-@sc{car} of the cons cell points to the element, and its @sc{cdr} points
-to the next cons cell of the list, which holds the next element in the
-list. The @sc{cdr} of the last cons cell is set to point to @code{nil}.
+@sc{car} slot of the cons cell holds the element, and its @sc{cdr}
+slot refers to the next cons cell of the list, which holds the next
+element in the list. The @sc{cdr} slot of the last cons cell is set to
+hold @code{nil}.
@cindex box diagrams, for lists
@cindex diagrams, boxed, for lists
A list can be illustrated by a diagram in which the cons cells are
-shown as pairs of boxes. (The Lisp reader cannot read such an
-illustration; unlike the textual notation, which can be understood by
-both humans and computers, the box illustrations can be understood only
-by humans.) The following represents the three-element list @code{(rose
-violet buttercup)}:
+shown as pairs of boxes, like dominoes. (The Lisp reader cannot read
+such an illustration; unlike the textual notation, which can be
+understood by both humans and computers, the box illustrations can be
+understood only by humans.) This picture represents the three-element
+list @code{(rose violet buttercup)}:
@example
@group
- ___ ___ ___ ___ ___ ___
- |___|___|--> |___|___|--> |___|___|--> nil
+ --- --- --- --- --- ---
+ | | |--> | | |--> | | |--> nil
+ --- --- --- --- --- ---
| | |
| | |
--> rose --> violet --> buttercup
@end group
@end example
- In this diagram, each box represents a slot that can refer to any Lisp
-object. Each pair of boxes represents a cons cell. Each arrow is a
-reference to a Lisp object, either an atom or another cons cell.
+ In this diagram, each box represents a slot that can hold or refer to
+any Lisp object. Each pair of boxes represents a cons cell. Each arrow
+represents a reference to a Lisp object, either an atom or another cons
+cell.
- In this example, the first box, the @sc{car} of the first cons cell,
-refers to or ``contains'' @code{rose} (a symbol). The second box, the
-@sc{cdr} of the first cons cell, refers to the next pair of boxes, the
-second cons cell. The @sc{car} of the second cons cell refers to
-@code{violet} and the @sc{cdr} refers to the third cons cell. The
-@sc{cdr} of the third (and last) cons cell refers to @code{nil}.
+ In this example, the first box, which holds the @sc{car} of the first
+cons cell, refers to or ``holds'' @code{rose} (a symbol). The second
+box, holding the @sc{cdr} of the first cons cell, refers to the next
+pair of boxes, the second cons cell. The @sc{car} of the second cons
+cell is @code{violet}, and its @sc{cdr} is the third cons cell. The
+@sc{cdr} of the third (and last) cons cell is @code{nil}.
-Here is another diagram of the same list, @code{(rose violet
+ Here is another diagram of the same list, @code{(rose violet
buttercup)}, sketched in a different manner:
@smallexample
@example
@group
- ___ ___ ___ ___
- |___|___|--> |___|___|--> nil
+ --- --- --- ---
+ | | |--> | | |--> nil
+ --- --- --- ---
| |
| |
--> A --> nil
@code{(@var{a} .@: @var{b})} stands for a cons cell whose @sc{car} is
the object @var{a}, and whose @sc{cdr} is the object @var{b}. Dotted
pair notation is therefore more general than list syntax. In the dotted
-pair notation, the list @samp{(1 2 3)} is written as @samp{(1 . (2 . (3
-. nil)))}. For @code{nil}-terminated lists, the two notations produce
-the same result, but list notation is usually clearer and more
-convenient when it is applicable. When printing a list, the dotted pair
-notation is only used if the @sc{cdr} of a cell is not a list.
+pair notation, the list @samp{(1 2 3)} is written as @samp{(1 . (2 . (3
+. nil)))}. For @code{nil}-terminated lists, you can use either
+notation, but list notation is usually clearer and more convenient.
+When printing a list, the dotted pair notation is only used if the
+@sc{cdr} of a cons cell is not a list.
- Here's how box notation can illustrate dotted pairs. This example
-shows the pair @code{(rose . violet)}:
+ Here's an example using boxes to illustrate dotted pair notation.
+This example shows the pair @code{(rose . violet)}:
@example
@group
- ___ ___
- |___|___|--> violet
+ --- ---
+ | | |--> violet
+ --- ---
|
|
--> rose
@end group
@end example
- Dotted pair notation can be combined with list notation to represent a
-chain of cons cells with a non-@code{nil} final @sc{cdr}. For example,
-@code{(rose violet . buttercup)} is equivalent to @code{(rose . (violet
-. buttercup))}. The object looks like this:
+ You can combine dotted pair notation with list notation to represent
+conveniently a chain of cons cells with a non-@code{nil} final @sc{cdr}.
+You write a dot after the last element of the list, followed by the
+@sc{cdr} of the final cons cell. For example, @code{(rose violet
+. buttercup)} is equivalent to @code{(rose . (violet . buttercup))}.
+The object looks like this:
@example
@group
- ___ ___ ___ ___
- |___|___|--> |___|___|--> buttercup
+ --- --- --- ---
+ | | |--> | | |--> buttercup
+ --- --- --- ---
| |
| |
--> rose --> violet
@end group
@end example
- These diagrams make it evident why @w{@code{(rose .@: violet .@:
-buttercup)}} is invalid syntax; it would require a cons cell that has
-three parts rather than two.
+ The syntax @code{(rose .@: violet .@: buttercup)} is invalid because
+there is nothing that it could mean. If anything, it would say to put
+@code{buttercup} in the @sc{cdr} of a cons cell whose @sc{cdr} is already
+used for @code{violet}.
- The list @code{(rose violet)} is equivalent to @code{(rose . (violet))}
+ The list @code{(rose violet)} is equivalent to @code{(rose . (violet))},
and looks like this:
@example
@group
- ___ ___ ___ ___
- |___|___|--> |___|___|--> nil
+ --- --- --- ---
+ | | |--> | | |--> nil
+ --- --- --- ---
| |
| |
--> rose --> violet
Similarly, the three-element list @code{(rose violet buttercup)}
is equivalent to @code{(rose . (violet . (buttercup)))}.
-@ifinfo
+@ifnottex
It looks like this:
@example
@group
- ___ ___ ___ ___ ___ ___
- |___|___|--> |___|___|--> |___|___|--> nil
+ --- --- --- --- --- ---
+ | | |--> | | |--> | | |--> nil
+ --- --- --- --- --- ---
| | |
| | |
--> rose --> violet --> buttercup
@end group
@end example
-@end ifinfo
+@end ifnottex
@node Association List Type
@comment node-name, next, previous, up
@example
(setq alist-of-colors
- '((rose . red) (lily . white) (buttercup . yellow)))
+ '((rose . red) (lily . white) (buttercup . yellow)))
@end example
@noindent
first element, @code{rose} is the key and @code{red} is the value.
@xref{Association Lists}, for a further explanation of alists and for
-functions that work on alists.
+functions that work on alists. @xref{Hash Tables}, for another kind of
+lookup table, which is much faster for handling a large number of keys.
@node Array Type
@subsection Array Type
An @dfn{array} is composed of an arbitrary number of slots for
-referring to other Lisp objects, arranged in a contiguous block of
-memory. Accessing any element of an array takes the same amount of
-time. In contrast, accessing an element of a list requires time
-proportional to the position of the element in the list. (Elements at
-the end of a list take longer to access than elements at the beginning
-of a list.)
-
- Emacs defines two types of array, strings and vectors. A string is an
-array of characters and a vector is an array of arbitrary objects. Both
-are one-dimensional. (Most other programming languages support
-multidimensional arrays, but they are not essential; you can get the
-same effect with an array of arrays.) Each type of array has its own
-read syntax; see @ref{String Type}, and @ref{Vector Type}.
-
- An array may have any length up to the largest integer; but once
-created, it has a fixed size. The first element of an array has index
-zero, the second element has index 1, and so on. This is called
-@dfn{zero-origin} indexing. For example, an array of four elements has
-indices 0, 1, 2, @w{and 3}.
-
- The array type is contained in the sequence type and contains both the
-string type and the vector type.
+holding or referring to other Lisp objects, arranged in a contiguous block of
+memory. Accessing any element of an array takes approximately the same
+amount of time. In contrast, accessing an element of a list requires
+time proportional to the position of the element in the list. (Elements
+at the end of a list take longer to access than elements at the
+beginning of a list.)
+
+ Emacs defines four types of array: strings, vectors, bool-vectors, and
+char-tables.
+
+ A string is an array of characters and a vector is an array of
+arbitrary objects. A bool-vector can hold only @code{t} or @code{nil}.
+These kinds of array may have any length up to the largest integer.
+Char-tables are sparse arrays indexed by any valid character code; they
+can hold arbitrary objects.
+
+ The first element of an array has index zero, the second element has
+index 1, and so on. This is called @dfn{zero-origin} indexing. For
+example, an array of four elements has indices 0, 1, 2, @w{and 3}. The
+largest possible index value is one less than the length of the array.
+Once an array is created, its length is fixed.
+
+ All Emacs Lisp arrays are one-dimensional. (Most other programming
+languages support multidimensional arrays, but they are not essential;
+you can get the same effect with an array of arrays.) Each type of
+array has its own read syntax; see the following sections for details.
+
+ The array type is contained in the sequence type and
+contains the string type, the vector type, the bool-vector type, and the
+char-table type.
@node String Type
@subsection String Type
in documentation strings,
but the newline is \
ignored if escaped."
- @result{} "It is useful to include newlines
-in documentation strings,
+ @result{} "It is useful to include newlines
+in documentation strings,
but the newline is ignored if escaped."
@end example
@node Non-ASCII in Strings
-@subsubsection Non-ASCII Characters in Strings
+@subsubsection Non-@sc{ascii} Characters in Strings
- You can include a non-@sc{ASCII} international character in a string
+ You can include a non-@sc{ascii} international character in a string
constant by writing it literally. There are two text representations
-for non-@sc{ASCII} characters in Emacs strings (and in buffers): unibyte
+for non-@sc{ascii} characters in Emacs strings (and in buffers): unibyte
and multibyte. If the string constant is read from a multibyte source,
-then the character is read as a multibyte character, and that makes the
-string multibyte. If the string constant is read from a unibyte source,
-then the character is read as unibyte and that makes the string unibyte.
-
- You can also represent a multibyte non-@sc{ASCII} character with its
-character code, using a hex escape, @samp{\x@var{nnnnnnn}}, with as many
-digits as necessary. (Multibyte non-@sc{ASCII} character codes are all
+such as a multibyte buffer or string, or a file that would be visited as
+multibyte, then the character is read as a multibyte character, and that
+makes the string multibyte. If the string constant is read from a
+unibyte source, then the character is read as unibyte and that makes the
+string unibyte.
+
+ You can also represent a multibyte non-@sc{ascii} character with its
+character code: use a hex escape, @samp{\x@var{nnnnnnn}}, with as many
+digits as necessary. (Multibyte non-@sc{ascii} character codes are all
greater than 256.) Any character which is not a valid hex digit
-terminates this construct. If the character that would follow is a hex
-digit, write @samp{\ } to terminate the hex escape---for example,
-@samp{\x8c0\ } represents one character, @samp{a} with grave accent.
-@samp{\ } in a string constant is just like backslash-newline; it does
-not contribute any character to the string, but it does terminate the
-preceding hex escape.
+terminates this construct. If the next character in the string could be
+interpreted as a hex digit, write @w{@samp{\ }} (backslash and space) to
+terminate the hex escape---for example, @w{@samp{\x8e0\ }} represents
+one character, @samp{a} with grave accent. @w{@samp{\ }} in a string
+constant is just like backslash-newline; it does not contribute any
+character to the string, but it does terminate the preceding hex escape.
Using a multibyte hex escape forces the string to multibyte. You can
-represent a unibyte non-@sc{ASCII} character with its character code,
+represent a unibyte non-@sc{ascii} character with its character code,
which must be in the range from 128 (0200 octal) to 255 (0377 octal).
This forces a unibyte string.
-
+
@xref{Text Representations}, for more information about the two
text representations.
@node Nonprinting Characters
@subsubsection Nonprinting Characters in Strings
- Strings cannot hold characters that have the hyper, super, or alt
-modifiers; the only control or meta characters they can hold are the
-@sc{ASCII} control characters. Strings do not distinguish case in
-@sc{ASCII} control characters.
-
You can use the same backslash escape-sequences in a string constant
as in character literals (but do not use the question mark that begins a
character constant). For example, you can write a string containing the
-nonprinting characters tab, @kbd{C-a} and @kbd{M-C-a}, with commas and
-spaces between them, like this: @code{"\t, \C-a, \M-\C-a"}.
-@xref{Character Type}, for a description of the read syntax for
-characters.
-
- If you use the @samp{\M-} syntax to indicate a meta character in a
-string constant, this sets the
-@iftex
-$2^{7}$
-@end iftex
-@ifinfo
+nonprinting characters tab and @kbd{C-a}, with commas and spaces between
+them, like this: @code{"\t, \C-a"}. @xref{Character Type}, for a
+description of the read syntax for characters.
+
+ However, not all of the characters you can write with backslash
+escape-sequences are valid in strings. The only control characters that
+a string can hold are the @sc{ascii} control characters. Strings do not
+distinguish case in @sc{ascii} control characters.
+
+ Properly speaking, strings cannot hold meta characters; but when a
+string is to be used as a key sequence, there is a special convention
+that provides a way to represent meta versions of @sc{ascii} characters in a
+string. If you use the @samp{\M-} syntax to indicate a meta character
+in a string constant, this sets the
+@tex
+@math{2^{7}}
+@end tex
+@ifnottex
2**7
-@end ifinfo
-bit of the character in the string. This construct works only with
-ASCII characters. Note that the same meta characters have a different
-representation when not in a string. @xref{Character Type}.
+@end ifnottex
+bit of the character in the string. If the string is used in
+@code{define-key} or @code{lookup-key}, this numeric code is translated
+into the equivalent meta character. @xref{Character Type}.
+
+ Strings cannot hold characters that have the hyper, super, or alt
+modifiers.
@node Text Props and Strings
@subsubsection Text Properties in Strings
represents a string whose textual contents are @samp{foo bar}, in which
the first three characters have a @code{face} property with value
@code{bold}, and the last three have a @code{face} property with value
-@code{italic}. (The fourth character has no text properties so its
-property list is @code{nil}.)
+@code{italic}. (The fourth character has no text properties, so its
+property list is @code{nil}. It is not actually necessary to mention
+ranges with @code{nil} as the property list, since any characters not
+mentioned in any range will default to having no properties.)
@node Vector Type
@subsection Vector Type
a whole character set.
The printed representation of a char-table is like a vector
-except that there is an extra @samp{#} at the beginning.
+except that there is an extra @samp{#^} at the beginning.
@xref{Char-Tables}, for special functions to operate on char-tables.
+Uses of char-tables include:
+
+@itemize @bullet
+@item
+Case tables (@pxref{Case Tables}).
+
+@item
+Character category tables (@pxref{Categories}).
+
+@item
+Display tables (@pxref{Display Tables}).
+
+@item
+Syntax tables (@pxref{Syntax Tables}).
+@end itemize
@node Bool-Vector Type
@subsection Bool-Vector Type
A @dfn{bool-vector} is a one-dimensional array of elements that
must be @code{t} or @code{nil}.
- The printed representation of a Bool-vector is like a string, except
+ The printed representation of a bool-vector is like a string, except
that it begins with @samp{#&} followed by the length. The string
constant that follows actually specifies the contents of the bool-vector
as a bitmap---each ``character'' in the string contains 8 bits, which
specify the next 8 elements of the bool-vector (1 stands for @code{t},
-and 0 for @code{nil}). If the length is not a multiple of 8, the
-printed representation describes extra elements, but these really
-make no difference.
+and 0 for @code{nil}). The least significant bits of the character
+correspond to the lowest indices in the bool-vector. If the length is not a
+multiple of 8, the printed representation shows extra elements, but
+these extras really make no difference.
@example
(make-bool-vector 3 t)
- @result{} #&3"\377"
+ @result{} #&3"\007"
(make-bool-vector 3 nil)
- @result{} #&3"\0""
+ @result{} #&3"\0"
+;; @r{These are equal since only the first 3 bits are used.}
+(equal #&3"\377" #&3"\007")
+ @result{} t
+@end example
+
+@node Hash Table Type
+@subsection Hash Table Type
+
+ A hash table is a very fast kind of lookup table, somewhat like an
+alist in that it maps keys to corresponding values, but much faster.
+Hash tables are a new feature in Emacs 21; they have no read syntax, and
+print using hash notation. @xref{Hash Tables}.
+
+@example
+(make-hash-table)
+ @result{} #<hash-table 'eql nil 0/65 0x83af980>
@end example
@node Function Type
A @dfn{Lisp macro} is a user-defined construct that extends the Lisp
language. It is represented as an object much like a function, but with
-different parameter-passing semantics. A Lisp macro has the form of a
+different argument-passing semantics. A Lisp macro has the form of a
list whose first element is the symbol @code{macro} and whose @sc{cdr}
is a Lisp function object, including the @code{lambda} symbol.
(@pxref{Special Forms}).@refill
It does not matter to the caller of a function whether the function is
-primitive. However, this does matter if you try to substitute a
-function written in Lisp for a primitive of the same name. The reason
-is that the primitive function may be called directly from C code.
-Calls to the redefined function from Lisp will use the new definition,
-but calls from C code may still use the built-in definition. Therefore,
-@strong{we discourage redefinition of primitive functions}.
+primitive. However, this does matter if you try to redefine a primitive
+with a function written in Lisp. The reason is that the primitive
+function may be called directly from C code. Calls to the redefined
+function from Lisp will use the new definition, but calls from C code
+may still use the built-in definition. Therefore, @strong{we discourage
+redefinition of primitive functions}.
The term @dfn{function} refers to all Emacs functions, whether written
in Lisp or C. @xref{Function Type}, for information about the
@subsection Autoload Type
An @dfn{autoload object} is a list whose first element is the symbol
-@code{autoload}. It is stored as the function definition of a symbol as
-a placeholder for the real definition; it says that the real definition
-is found in a file of Lisp code that should be loaded when necessary.
-The autoload object contains the name of the file, plus some other
-information about the real definition.
+@code{autoload}. It is stored as the function definition of a symbol,
+where it serves as a placeholder for the real definition. The autoload
+object says that the real definition is found in a file of Lisp code
+that should be loaded when necessary. It contains the name of the file,
+plus some other information about the real definition.
After the file has been loaded, the symbol should have a new function
definition that is not an autoload object. The new definition is then
@section Editing Types
@cindex editing types
- The types in the previous section are common to many Lisp dialects.
-Emacs Lisp provides several additional data types for purposes connected
-with editing.
+ The types in the previous section are used for general programming
+purposes, and most of them are common to most Lisp dialects. Emacs Lisp
+provides several additional data types for purposes connected with
+editing.
@menu
* Buffer Type:: The basic object of editing.
* Window Type:: Buffers are displayed in windows.
* Frame Type:: Windows subdivide frames.
* Window Configuration Type:: Recording the way a frame is subdivided.
+* Frame Configuration Type:: Recording the status of all frames.
* Process Type:: A process running on the underlying OS.
* Stream Type:: Receive or send characters.
* Keymap Type:: What function a keystroke invokes.
-* Syntax Table Type:: What a character means.
-* Display Table Type:: How display tables are represented.
* Overlay Type:: How an overlay is represented.
@end menu
The contents of a buffer are much like a string, but buffers are not
used like strings in Emacs Lisp, and the available operations are
-different. For example, insertion of text into a buffer is very
-efficient, whereas ``inserting'' text into a string requires
-concatenating substrings, and the result is an entirely new string
-object.
+different. For example, you can insert text efficiently into an
+existing buffer, altering the buffer's contents, whereas ``inserting''
+text into a string requires concatenating substrings, and the result is
+an entirely new string object.
Each buffer has a designated position called @dfn{point}
(@pxref{Positions}). At any time, one buffer is the @dfn{current
a local keymap (@pxref{Keymaps}); and,
@item
-a local variable binding list (@pxref{Buffer-Local Variables}).
+a list of buffer-local variable bindings (@pxref{Buffer-Local Variables}).
@item
-a list of overlays (@pxref{Overlays}).
+overlays (@pxref{Overlays}).
@item
text properties for the text in the buffer (@pxref{Text Properties}).
programs.
A buffer may be @dfn{indirect}, which means it shares the text
-of another buffer. @xref{Indirect Buffers}.
+of another buffer, but presents it differently. @xref{Indirect Buffers}.
Buffers have no read syntax. They print in hash notation, showing the
buffer name.
@node Frame Type
@subsection Frame Type
- A @var{frame} is a rectangle on the screen that contains one or more
+ A @dfn{frame} is a rectangle on the screen that contains one or more
Emacs windows. A frame initially contains a single main window (plus
perhaps a minibuffer window) which you can subdivide vertically or
horizontally into smaller windows.
@example
@group
(selected-frame)
- @result{} #<frame xemacs@@mole.gnu.ai.mit.edu 0xdac80>
+ @result{} #<frame emacs@@psilocin.gnu.org 0xdac80>
@end group
@end example
Configurations}, for a description of several functions related to
window configurations.
+@node Frame Configuration Type
+@subsection Frame Configuration Type
+@cindex screen layout
+
+ A @dfn{frame configuration} stores information about the positions,
+sizes, and contents of the windows in all frames. It is actually
+a list whose @sc{car} is @code{frame-configuration} and whose
+@sc{cdr} is an alist. Each alist element describes one frame,
+which appears as the @sc{car} of that element.
+
+ @xref{Frame Configurations}, for a description of several functions
+related to frame configurations.
+
@node Process Type
@subsection Process Type
@xref{Keymaps}, for information about creating keymaps, handling prefix
keys, local as well as global keymaps, and changing key bindings.
-@node Syntax Table Type
-@subsection Syntax Table Type
-
- A @dfn{syntax table} is a char-table which specifies the syntax of
-each character, for word and list parsing. Each element of the syntax
-table defines how one character is interpreted when it appears in a
-buffer. For example, in C mode (@pxref{Major Modes}), the @samp{+}
-character is punctuation, but in Lisp mode it is a valid character in a
-symbol. These modes specify different interpretations by changing the
-syntax table entry for @samp{+}, at index 43 in the syntax table.
-
- Syntax tables are used only to control primitives that scan text in
-buffers, not for reading Lisp expressions. The syntax that the Lisp
-interpreter uses to read expressions is built into the Emacs source code
-and cannot be changed; thus, to change the list delimiters to be
-@samp{@{} and @samp{@}} instead of @samp{(} and @samp{)} would be
-impossible. (Some Lisp systems provide ways to redefine the read
-syntax, but we decided to leave this feature out of Emacs Lisp for
-simplicity.)
-
- @xref{Syntax Tables}, for details about syntax classes and how to make
-and modify syntax tables.
-
-@node Display Table Type
-@subsection Display Table Type
-
- A @dfn{display table} specifies how to display each character code.
-Each buffer and each window can have its own display table. A display
-table is actually a char-table. @xref{Display Tables}.
-
@node Overlay Type
@subsection Overlay Type
@xref{Overlays}, for how to create and use overlays.
+@node Circular Objects
+@section Read Syntax for Circular Objects
+@cindex circular structure, read syntax
+@cindex shared structure, read syntax
+@cindex @samp{#@var{n}=} read syntax
+@cindex @samp{#@var{n}#} read syntax
+
+ In Emacs 21, to represent shared or circular structure within a
+complex of Lisp objects, you can use the reader constructs
+@samp{#@var{n}=} and @samp{#@var{n}#}.
+
+ Use @code{#@var{n}=} before an object to label it for later reference;
+subsequently, you can use @code{#@var{n}#} to refer the same object in
+another place. Here, @var{n} is some integer. For example, here is how
+to make a list in which the first element recurs as the third element:
+
+@example
+(#1=(a) b #1#)
+@end example
+
+@noindent
+This differs from ordinary syntax such as this
+
+@example
+((a) b (a))
+@end example
+
+@noindent
+which would result in a list whose first and third elements
+look alike but are not the same Lisp object. This shows the difference:
+
+@example
+(prog1 nil
+ (setq x '(#1=(a) b #1#)))
+(eq (nth 0 x) (nth 2 x))
+ @result{} t
+(setq x '((a) b (a)))
+(eq (nth 0 x) (nth 2 x))
+ @result{} nil
+@end example
+
+ You can also use the same syntax to make a circular structure, which
+appears as an ``element'' within itself. Here is an example:
+
+@example
+#1=(a #1#)
+@end example
+
+@noindent
+This makes a list whose second element is the list itself.
+Here's how you can see that it really works:
+
+@example
+(prog1 nil
+ (setq x '#1=(a #1#)))
+(eq x (cadr x))
+ @result{} t
+@end example
+
+ The Lisp printer can produce this syntax to record circular and shared
+structure in a Lisp object, if you bind the variable @code{print-circle}
+to a non-@code{nil} value. @xref{Output Variables}.
+
@node Type Predicates
@section Type Predicates
@cindex predicates
((listp x)
;; If X is a list, add its elements to LIST.
(setq list (append x list)))
-@need 3000
(t
- ;; We only handle symbols and lists.
+ ;; We handle only symbols and lists.
(error "Invalid argument %s in add-on" x))))
@end example
@item arrayp
@xref{Array Functions, arrayp}.
+@item bool-vector-p
+@xref{Bool-Vectors, bool-vector-p}.
+
@item bufferp
@xref{Buffer Basics, bufferp}.
@xref{Byte-Code Type, byte-code-function-p}.
@item case-table-p
-@xref{Case Table, case-table-p}.
+@xref{Case Tables, case-table-p}.
@item char-or-string-p
@xref{Predicates for Strings, char-or-string-p}.
+@item char-table-p
+@xref{Char-Tables, char-table-p}.
+
@item commandp
@xref{Interactive Call, commandp}.
@item consp
@xref{List-related Predicates, consp}.
+@item display-table-p
+@xref{Display Tables, display-table-p}.
+
@item floatp
@xref{Predicates on Numbers, floatp}.
+@item frame-configuration-p
+@xref{Frame Configurations, frame-configuration-p}.
+
@item frame-live-p
@xref{Deleting Frames, frame-live-p}.
@item keymapp
@xref{Creating Keymaps, keymapp}.
+@item keywordp
+@xref{Constant Variables}.
+
@item listp
@xref{List-related Predicates, listp}.
This function returns a symbol naming the primitive type of
@var{object}. The value is one of the symbols @code{symbol},
@code{integer}, @code{float}, @code{string}, @code{cons}, @code{vector},
-@code{marker}, @code{overlay}, @code{window}, @code{buffer},
-@code{subr}, @code{compiled-function}, @code{process}, or
+@code{char-table}, @code{bool-vector}, @code{hash-table}, @code{subr},
+@code{compiled-function}, @code{marker}, @code{overlay}, @code{window},
+@code{buffer}, @code{frame}, @code{process}, or
@code{window-configuration}.
@example
@code{eq} to each other: they are @code{eq} only if they are the same
object.
-(The @code{make-symbol} function returns an uninterned symbol that is
-not interned in the standard @code{obarray}. When uninterned symbols
-are in use, symbol names are no longer unique. Distinct symbols with
-the same name are not @code{eq}. @xref{Creating Symbols}.)
-
@example
@group
(eq 'foo 'foo)
@end group
@end example
+The @code{make-symbol} function returns an uninterned symbol, distinct
+from the symbol that is used if you write the name in a Lisp expression.
+Distinct symbols with the same name are not @code{eq}. @xref{Creating
+Symbols}.
+
+@example
+@group
+(eq (make-symbol "foo") 'foo)
+ @result{} nil
+@end group
+@end example
@end defun
@defun equal object1 object2
This function returns @code{t} if @var{object1} and @var{object2} have
equal components, @code{nil} otherwise. Whereas @code{eq} tests if its
arguments are the same object, @code{equal} looks inside nonidentical
-arguments to see if their elements are the same. So, if two objects are
-@code{eq}, they are @code{equal}, but the converse is not always true.
+arguments to see if their elements or contents are the same. So, if two
+objects are @code{eq}, they are @code{equal}, but the converse is not
+always true.
@example
@group
Comparison of strings is case-sensitive, but does not take account of
text properties---it compares only the characters in the strings.
A unibyte string never equals a multibyte string unless the
-contents are entirely @sc{ASCII} (@pxref{Text Representations}).
+contents are entirely @sc{ascii} (@pxref{Text Representations}).
@example
@group
@end group
@end example
-Two distinct buffers are never @code{equal}, even if their contents
-are the same.
+However, two distinct buffers are never considered @code{equal}, even if
+their textual contents are the same.
@end defun
- The test for equality is implemented recursively, and circular lists may
-therefore cause infinite recursion (leading to an error).
+ The test for equality is implemented recursively; for example, given
+two cons cells @var{x} and @var{y}, @code{(equal @var{x} @var{y})}
+returns @code{t} if and only if both the expressions below return
+@code{t}:
+
+@example
+(equal (car @var{x}) (car @var{y}))
+(equal (cdr @var{x}) (cdr @var{y}))
+@end example
+
+Because of this recursive method, circular lists may therefore cause
+infinite recursion (leading to an error).