aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlenn Morris2012-10-24 00:41:11 -0700
committerGlenn Morris2012-10-24 00:41:11 -0700
commit39a58b5b51a881b4960600814653c3efd8e1ffb9 (patch)
tree53feccf0a34e74a4ce4dfe9dc0cb62277923314f
parent72ec96fb41e2e53ac5fda7532b0d3753e5ff971e (diff)
downloademacs-39a58b5b51a881b4960600814653c3efd8e1ffb9.tar.gz
emacs-39a58b5b51a881b4960600814653c3efd8e1ffb9.zip
Further namespace updates for cl.texi
* doc/misc/cl.texi (Basic Setf, Macros, Declarations, Symbols, Numbers) (Sequences, Lists, Structures, Assertions, Efficiency Concerns) (Efficiency Concerns, Efficiency Concerns) (Common Lisp Compatibility, Old CL Compatibility): Further updates for cl-lib namespace.
-rw-r--r--doc/misc/ChangeLog8
-rw-r--r--doc/misc/cl.texi1131
2 files changed, 575 insertions, 564 deletions
diff --git a/doc/misc/ChangeLog b/doc/misc/ChangeLog
index 5535fdd77f0..76859e09d42 100644
--- a/doc/misc/ChangeLog
+++ b/doc/misc/ChangeLog
@@ -1,3 +1,11 @@
12012-10-24 Glenn Morris <rgm@gnu.org>
2
3 * cl.texi (Basic Setf, Macros, Declarations, Symbols, Numbers)
4 (Sequences, Lists, Structures, Assertions, Efficiency Concerns)
5 (Efficiency Concerns, Efficiency Concerns)
6 (Common Lisp Compatibility, Old CL Compatibility):
7 Further updates for cl-lib namespace.
8
12012-10-24 Paul Eggert <eggert@penguin.cs.ucla.edu> 92012-10-24 Paul Eggert <eggert@penguin.cs.ucla.edu>
2 10
3 Update manual for new time stamp format (Bug#12706). 11 Update manual for new time stamp format (Bug#12706).
diff --git a/doc/misc/cl.texi b/doc/misc/cl.texi
index 12fd76e2e1c..5908e94be02 100644
--- a/doc/misc/cl.texi
+++ b/doc/misc/cl.texi
@@ -1047,11 +1047,11 @@ The @code{setf} macro takes care to evaluate all subforms in
1047the proper left-to-right order; for example, 1047the proper left-to-right order; for example,
1048 1048
1049@example 1049@example
1050(setf (aref vec (incf i)) i) 1050(setf (aref vec (cl-incf i)) i)
1051@end example 1051@end example
1052 1052
1053@noindent 1053@noindent
1054looks like it will evaluate @code{(incf i)} exactly once, before the 1054looks like it will evaluate @code{(cl-incf i)} exactly once, before the
1055following access to @code{i}; the @code{setf} expander will insert 1055following access to @code{i}; the @code{setf} expander will insert
1056temporary variables as necessary to ensure that it does in fact work 1056temporary variables as necessary to ensure that it does in fact work
1057this way no matter what setf-method is defined for @code{aref}. 1057this way no matter what setf-method is defined for @code{aref}.
@@ -1081,7 +1081,7 @@ This package defines a number of other macros besides @code{setf}
1081that operate on generalized variables. Many are interesting and 1081that operate on generalized variables. Many are interesting and
1082useful even when the @var{place} is just a variable name. 1082useful even when the @var{place} is just a variable name.
1083 1083
1084@defspec psetf [place form]@dots{} 1084@defspec cl-psetf [place form]@dots{}
1085This macro is to @code{setf} what @code{cl-psetq} is to @code{setq}: 1085This macro is to @code{setf} what @code{cl-psetq} is to @code{setq}:
1086When several @var{place}s and @var{form}s are involved, the 1086When several @var{place}s and @var{form}s are involved, the
1087assignments take place in parallel rather than sequentially. 1087assignments take place in parallel rather than sequentially.
@@ -1089,17 +1089,17 @@ Specifically, all subforms are evaluated from left to right, then
1089all the assignments are done (in an undefined order). 1089all the assignments are done (in an undefined order).
1090@end defspec 1090@end defspec
1091 1091
1092@defspec incf place &optional x 1092@defspec cl-incf place &optional x
1093This macro increments the number stored in @var{place} by one, or 1093This macro increments the number stored in @var{place} by one, or
1094by @var{x} if specified. The incremented value is returned. For 1094by @var{x} if specified. The incremented value is returned. For
1095example, @code{(incf i)} is equivalent to @code{(setq i (1+ i))}, and 1095example, @code{(cl-incf i)} is equivalent to @code{(setq i (1+ i))}, and
1096@code{(incf (car x) 2)} is equivalent to @code{(setcar x (+ (car x) 2))}. 1096@code{(cl-incf (car x) 2)} is equivalent to @code{(setcar x (+ (car x) 2))}.
1097 1097
1098Once again, care is taken to preserve the ``apparent'' order of 1098Once again, care is taken to preserve the ``apparent'' order of
1099evaluation. For example, 1099evaluation. For example,
1100 1100
1101@example 1101@example
1102(incf (aref vec (incf i))) 1102(cl-incf (aref vec (cl-incf i)))
1103@end example 1103@end example
1104 1104
1105@noindent 1105@noindent
@@ -1109,27 +1109,27 @@ does, which means the above form is @emph{not} equivalent to the
1109``obvious'' expansion, 1109``obvious'' expansion,
1110 1110
1111@example 1111@example
1112(setf (aref vec (incf i)) (1+ (aref vec (incf i)))) ; Wrong! 1112(setf (aref vec (cl-incf i)) (1+ (aref vec (cl-incf i)))) ; Wrong!
1113@end example 1113@end example
1114 1114
1115@noindent 1115@noindent
1116but rather to something more like 1116but rather to something more like
1117 1117
1118@example 1118@example
1119(let ((temp (incf i))) 1119(let ((temp (cl-incf i)))
1120 (setf (aref vec temp) (1+ (aref vec temp)))) 1120 (setf (aref vec temp) (1+ (aref vec temp))))
1121@end example 1121@end example
1122 1122
1123@noindent 1123@noindent
1124Again, all of this is taken care of automatically by @code{incf} and 1124Again, all of this is taken care of automatically by @code{cl-incf} and
1125the other generalized-variable macros. 1125the other generalized-variable macros.
1126 1126
1127As a more Emacs-specific example of @code{incf}, the expression 1127As a more Emacs-specific example of @code{cl-incf}, the expression
1128@code{(incf (point) @var{n})} is essentially equivalent to 1128@code{(cl-incf (point) @var{n})} is essentially equivalent to
1129@code{(forward-char @var{n})}. 1129@code{(forward-char @var{n})}.
1130@end defspec 1130@end defspec
1131 1131
1132@defspec decf place &optional x 1132@defspec cl-decf place &optional x
1133This macro decrements the number stored in @var{place} by one, or 1133This macro decrements the number stored in @var{place} by one, or
1134by @var{x} if specified. 1134by @var{x} if specified.
1135@end defspec 1135@end defspec
@@ -1256,7 +1256,7 @@ It does the bindings in sequential rather than parallel order.
1256This is the ``generic'' modify macro. It calls @var{function}, 1256This is the ``generic'' modify macro. It calls @var{function},
1257which should be an unquoted function name, macro name, or lambda. 1257which should be an unquoted function name, macro name, or lambda.
1258It passes @var{place} and @var{args} as arguments, and assigns the 1258It passes @var{place} and @var{args} as arguments, and assigns the
1259result back to @var{place}. For example, @code{(incf @var{place} 1259result back to @var{place}. For example, @code{(cl-incf @var{place}
1260@var{n})} is the same as @code{(callf + @var{place} @var{n})}. 1260@var{n})} is the same as @code{(callf + @var{place} @var{n})}.
1261Some more examples: 1261Some more examples:
1262 1262
@@ -1279,7 +1279,7 @@ equivalent to @code{(callf2 cons @var{x} @var{place})}.
1279@end defspec 1279@end defspec
1280 1280
1281The @code{callf} and @code{callf2} macros serve as building 1281The @code{callf} and @code{callf2} macros serve as building
1282blocks for other macros like @code{incf}, @code{pushnew}, and 1282blocks for other macros like @code{cl-incf}, @code{pushnew}, and
1283@code{define-modify-macro}. The @code{letf} and @code{letf*} 1283@code{define-modify-macro}. The @code{letf} and @code{letf*}
1284macros are used in the processing of symbol macros; 1284macros are used in the processing of symbol macros;
1285@pxref{Macro Bindings}. 1285@pxref{Macro Bindings}.
@@ -1294,7 +1294,7 @@ user to extend generalized variables in various ways.
1294 1294
1295@defspec define-modify-macro name arglist function [doc-string] 1295@defspec define-modify-macro name arglist function [doc-string]
1296This macro defines a ``read-modify-write'' macro similar to 1296This macro defines a ``read-modify-write'' macro similar to
1297@code{incf} and @code{decf}. The macro @var{name} is defined 1297@code{cl-incf} and @code{cl-decf}. The macro @var{name} is defined
1298to take a @var{place} argument followed by additional arguments 1298to take a @var{place} argument followed by additional arguments
1299described by @var{arglist}. The call 1299described by @var{arglist}. The call
1300 1300
@@ -1306,7 +1306,7 @@ described by @var{arglist}. The call
1306will be expanded to 1306will be expanded to
1307 1307
1308@example 1308@example
1309(callf @var{func} @var{place} @var{args}...) 1309(cl-callf @var{func} @var{place} @var{args}...)
1310@end example 1310@end example
1311 1311
1312@noindent 1312@noindent
@@ -1319,8 +1319,8 @@ which in turn is roughly equivalent to
1319For example: 1319For example:
1320 1320
1321@example 1321@example
1322(define-modify-macro incf (&optional (n 1)) +) 1322(define-modify-macro cl-incf (&optional (n 1)) +)
1323(define-modify-macro concatf (&rest args) concat) 1323(define-modify-macro cl-concatf (&rest args) concat)
1324@end example 1324@end example
1325 1325
1326Note that @code{&key} is not allowed in @var{arglist}, but 1326Note that @code{&key} is not allowed in @var{arglist}, but
@@ -1399,7 +1399,7 @@ For example, the simple form of @code{defsetf} is shorthand for
1399 1399
1400The Lisp form that is returned can access the arguments from 1400The Lisp form that is returned can access the arguments from
1401@var{arglist} and @var{store-var} in an unrestricted fashion; 1401@var{arglist} and @var{store-var} in an unrestricted fashion;
1402macros like @code{setf} and @code{incf} which invoke this 1402macros like @code{setf} and @code{cl-incf} which invoke this
1403setf-method will insert temporary variables as needed to make 1403setf-method will insert temporary variables as needed to make
1404sure the apparent order of evaluation is preserved. 1404sure the apparent order of evaluation is preserved.
1405 1405
@@ -1452,7 +1452,7 @@ temporary variables. In the setf-methods generated by
1452@code{defsetf}, the second return value is simply the list of 1452@code{defsetf}, the second return value is simply the list of
1453arguments in the place form, and the first return value is a 1453arguments in the place form, and the first return value is a
1454list of a corresponding number of temporary variables generated 1454list of a corresponding number of temporary variables generated
1455by @code{gensym}. Macros like @code{setf} and @code{incf} which 1455by @code{cl-gensym}. Macros like @code{setf} and @code{cl-incf} which
1456use this setf-method will optimize away most temporaries that 1456use this setf-method will optimize away most temporaries that
1457turn out to be unnecessary, so there is little reason for the 1457turn out to be unnecessary, so there is little reason for the
1458setf-method itself to optimize. 1458setf-method itself to optimize.
@@ -1463,11 +1463,12 @@ This function returns the setf-method for @var{place}, by
1463invoking the definition previously recorded by @code{defsetf} 1463invoking the definition previously recorded by @code{defsetf}
1464or @code{define-setf-method}. The result is a list of five 1464or @code{define-setf-method}. The result is a list of five
1465values as described above. You can use this function to build 1465values as described above. You can use this function to build
1466your own @code{incf}-like modify macros. (Actually, it is 1466your own @code{cl-incf}-like modify macros. (Actually, it is
1467@c FIXME?
1467better to use the internal functions @code{cl-setf-do-modify} 1468better to use the internal functions @code{cl-setf-do-modify}
1468and @code{cl-setf-do-store}, which are a bit easier to use and 1469and @code{cl-setf-do-store}, which are a bit easier to use and
1469which also do a number of optimizations; consult the source 1470which also do a number of optimizations; consult the source
1470code for the @code{incf} function for a simple example.) 1471code for the @code{cl-incf} function for a simple example.)
1471 1472
1472The argument @var{env} specifies the ``environment'' to be 1473The argument @var{env} specifies the ``environment'' to be
1473passed on to @code{macroexpand} if @code{get-setf-method} should 1474passed on to @code{macroexpand} if @code{get-setf-method} should
@@ -1504,14 +1505,14 @@ defined later.
1504These Lisp forms make bindings to variables and function names, 1505These Lisp forms make bindings to variables and function names,
1505analogous to Lisp's built-in @code{let} form. 1506analogous to Lisp's built-in @code{let} form.
1506 1507
1507@xref{Modify Macros}, for the @code{letf} and @code{letf*} forms which 1508@xref{Modify Macros}, for the @code{letf} and @code{cl-letf*} forms which
1508are also related to variable bindings. 1509are also related to variable bindings.
1509 1510
1510@menu 1511@menu
1511* Dynamic Bindings:: The @code{progv} form. 1512* Dynamic Bindings:: The @code{cl-progv} form.
1512* Lexical Bindings:: @code{lexical-let} and lexical closures. 1513* Lexical Bindings:: @code{lexical-let} and lexical closures.
1513* Function Bindings:: @code{flet} and @code{labels}. 1514* Function Bindings:: @code{flet} and @code{labels}.
1514* Macro Bindings:: @code{macrolet} and @code{symbol-macrolet}. 1515* Macro Bindings:: @code{cl-macrolet} and @code{cl-symbol-macrolet}.
1515@end menu 1516@end menu
1516 1517
1517@node Dynamic Bindings 1518@node Dynamic Bindings
@@ -1519,10 +1520,10 @@ are also related to variable bindings.
1519 1520
1520@noindent 1521@noindent
1521The standard @code{let} form binds variables whose names are known 1522The standard @code{let} form binds variables whose names are known
1522at compile-time. The @code{progv} form provides an easy way to 1523at compile-time. The @code{cl-progv} form provides an easy way to
1523bind variables whose names are computed at run-time. 1524bind variables whose names are computed at run-time.
1524 1525
1525@defspec progv symbols values forms@dots{} 1526@defspec cl-progv symbols values forms@dots{}
1526This form establishes @code{let}-style variable bindings on a 1527This form establishes @code{let}-style variable bindings on a
1527set of variables computed at run-time. The expressions 1528set of variables computed at run-time. The expressions
1528@var{symbols} and @var{values} are evaluated, and must return lists 1529@var{symbols} and @var{values} are evaluated, and must return lists
@@ -1587,7 +1588,7 @@ call to @code{make-adder} itself.
1587@example 1588@example
1588(defun make-counter () 1589(defun make-counter ()
1589 (lexical-let ((n 0)) 1590 (lexical-let ((n 0))
1590 (function* (lambda (&optional (m 1)) (incf n m))))) 1591 (cl-function (lambda (&optional (m 1)) (cl-incf n m)))))
1591(setq count-1 (make-counter)) 1592(setq count-1 (make-counter))
1592(funcall count-1 3) 1593(funcall count-1 3)
1593 @result{} 3 1594 @result{} 3
@@ -1696,8 +1697,8 @@ handling. Attempts to redefine such functions using @code{flet} will
1696fail if byte-compiled. In such cases, use @code{labels} instead. 1697fail if byte-compiled. In such cases, use @code{labels} instead.
1697 1698
1698Functions defined by @code{flet} may use the full Common Lisp 1699Functions defined by @code{flet} may use the full Common Lisp
1699argument notation supported by @code{defun*}; also, the function 1700argument notation supported by @code{cl-defun}; also, the function
1700body is enclosed in an implicit block as if by @code{defun*}. 1701body is enclosed in an implicit block as if by @code{cl-defun}.
1701@xref{Program Structure}. 1702@xref{Program Structure}.
1702@end defspec 1703@end defspec
1703 1704
@@ -1730,21 +1731,21 @@ function, or a use of its name quoted by @code{quote} or
1730@noindent 1731@noindent
1731These forms create local macros and ``symbol macros.'' 1732These forms create local macros and ``symbol macros.''
1732 1733
1733@defspec macrolet (bindings@dots{}) forms@dots{} 1734@defspec cl-macrolet (bindings@dots{}) forms@dots{}
1734This form is analogous to @code{flet}, but for macros instead of 1735This form is analogous to @code{flet}, but for macros instead of
1735functions. Each @var{binding} is a list of the same form as the 1736functions. Each @var{binding} is a list of the same form as the
1736arguments to @code{defmacro*} (i.e., a macro name, argument list, 1737arguments to @code{cl-defmacro} (i.e., a macro name, argument list,
1737and macro-expander forms). The macro is defined accordingly for 1738and macro-expander forms). The macro is defined accordingly for
1738use within the body of the @code{macrolet}. 1739use within the body of the @code{cl-macrolet}.
1739 1740
1740Because of the nature of macros, @code{macrolet} is lexically 1741Because of the nature of macros, @code{cl-macrolet} is lexically
1741scoped even in Emacs Lisp: The @code{macrolet} binding will 1742scoped even in Emacs Lisp: The @code{cl-macrolet} binding will
1742affect only calls that appear physically within the body 1743affect only calls that appear physically within the body
1743@var{forms}, possibly after expansion of other macros in the 1744@var{forms}, possibly after expansion of other macros in the
1744body. 1745body.
1745@end defspec 1746@end defspec
1746 1747
1747@defspec symbol-macrolet (bindings@dots{}) forms@dots{} 1748@defspec cl-symbol-macrolet (bindings@dots{}) forms@dots{}
1748This form creates @dfn{symbol macros}, which are macros that look 1749This form creates @dfn{symbol macros}, which are macros that look
1749like variable references rather than function calls. Each 1750like variable references rather than function calls. Each
1750@var{binding} is a list @samp{(@var{var} @var{expansion})}; 1751@var{binding} is a list @samp{(@var{var} @var{expansion})};
@@ -1753,8 +1754,8 @@ replaced by @var{expansion}.
1753 1754
1754@example 1755@example
1755(setq bar '(5 . 9)) 1756(setq bar '(5 . 9))
1756(symbol-macrolet ((foo (car bar))) 1757(cl-symbol-macrolet ((foo (car bar)))
1757 (incf foo)) 1758 (cl-incf foo))
1758bar 1759bar
1759 @result{} (6 . 9) 1760 @result{} (6 . 9)
1760@end example 1761@end example
@@ -1766,23 +1767,23 @@ I.e., @code{(setq foo 4)} in the above would be equivalent to
1766Likewise, a @code{let} or @code{let*} binding a symbol macro is 1767Likewise, a @code{let} or @code{let*} binding a symbol macro is
1767treated like a @code{letf} or @code{letf*}. This differs from true 1768treated like a @code{letf} or @code{letf*}. This differs from true
1768Common Lisp, where the rules of lexical scoping cause a @code{let} 1769Common Lisp, where the rules of lexical scoping cause a @code{let}
1769binding to shadow a @code{symbol-macrolet} binding. In this package, 1770binding to shadow a @code{cl-symbol-macrolet} binding. In this package,
1770only @code{lexical-let} and @code{lexical-let*} will shadow a symbol 1771only @code{lexical-let} and @code{lexical-let*} will shadow a symbol
1771macro. 1772macro.
1772 1773
1773There is no analogue of @code{defmacro} for symbol macros; all symbol 1774There is no analogue of @code{defmacro} for symbol macros; all symbol
1774macros are local. A typical use of @code{symbol-macrolet} is in the 1775macros are local. A typical use of @code{cl-symbol-macrolet} is in the
1775expansion of another macro: 1776expansion of another macro:
1776 1777
1777@example 1778@example
1778(defmacro* my-dolist ((x list) &rest body) 1779(cl-defmacro my-dolist ((x list) &rest body)
1779 (let ((var (gensym))) 1780 (let ((var (gensym)))
1780 (list 'loop 'for var 'on list 'do 1781 (list 'cl-loop 'for var 'on list 'do
1781 (list* 'symbol-macrolet (list (list x (list 'car var))) 1782 (cl-list* 'cl-symbol-macrolet (list (list x (list 'car var)))
1782 body)))) 1783 body))))
1783 1784
1784(setq mylist '(1 2 3 4)) 1785(setq mylist '(1 2 3 4))
1785(my-dolist (x mylist) (incf x)) 1786(my-dolist (x mylist) (cl-incf x))
1786mylist 1787mylist
1787 @result{} (2 3 4 5) 1788 @result{} (2 3 4 5)
1788@end example 1789@end example
@@ -1794,19 +1795,19 @@ reference onto the elements of the list. The @code{my-dolist} call
1794shown here expands to 1795shown here expands to
1795 1796
1796@example 1797@example
1797(loop for G1234 on mylist do 1798(cl-loop for G1234 on mylist do
1798 (symbol-macrolet ((x (car G1234))) 1799 (cl-symbol-macrolet ((x (car G1234)))
1799 (incf x))) 1800 (cl-incf x)))
1800@end example 1801@end example
1801 1802
1802@noindent 1803@noindent
1803which in turn expands to 1804which in turn expands to
1804 1805
1805@example 1806@example
1806(loop for G1234 on mylist do (incf (car G1234))) 1807(cl-loop for G1234 on mylist do (cl-incf (car G1234)))
1807@end example 1808@end example
1808 1809
1809@xref{Loop Facility}, for a description of the @code{loop} macro. 1810@xref{Loop Facility}, for a description of the @code{cl-loop} macro.
1810This package defines a nonstandard @code{in-ref} loop clause that 1811This package defines a nonstandard @code{in-ref} loop clause that
1811works much like @code{my-dolist}. 1812works much like @code{my-dolist}.
1812@end defspec 1813@end defspec
@@ -1818,11 +1819,11 @@ works much like @code{my-dolist}.
1818These conditional forms augment Emacs Lisp's simple @code{if}, 1819These conditional forms augment Emacs Lisp's simple @code{if},
1819@code{and}, @code{or}, and @code{cond} forms. 1820@code{and}, @code{or}, and @code{cond} forms.
1820 1821
1821@defspec case keyform clause@dots{} 1822@defspec cl-case keyform clause@dots{}
1822This macro evaluates @var{keyform}, then compares it with the key 1823This macro evaluates @var{keyform}, then compares it with the key
1823values listed in the various @var{clause}s. Whichever clause matches 1824values listed in the various @var{clause}s. Whichever clause matches
1824the key is executed; comparison is done by @code{eql}. If no clause 1825the key is executed; comparison is done by @code{eql}. If no clause
1825matches, the @code{case} form returns @code{nil}. The clauses are 1826matches, the @code{cl-case} form returns @code{nil}. The clauses are
1826of the form 1827of the form
1827 1828
1828@example 1829@example
@@ -1846,7 +1847,7 @@ four things depending on whether it is an @samp{a}, a @samp{b},
1846a @key{RET} or @kbd{C-j}, or anything else. 1847a @key{RET} or @kbd{C-j}, or anything else.
1847 1848
1848@example 1849@example
1849(case (read-char) 1850(cl-case (read-char)
1850 (?a (do-a-thing)) 1851 (?a (do-a-thing))
1851 (?b (do-b-thing)) 1852 (?b (do-b-thing))
1852 ((?\r ?\n) (do-ret-thing)) 1853 ((?\r ?\n) (do-ret-thing))
@@ -1854,20 +1855,20 @@ a @key{RET} or @kbd{C-j}, or anything else.
1854@end example 1855@end example
1855@end defspec 1856@end defspec
1856 1857
1857@defspec ecase keyform clause@dots{} 1858@defspec cl-ecase keyform clause@dots{}
1858This macro is just like @code{case}, except that if the key does 1859This macro is just like @code{cl-case}, except that if the key does
1859not match any of the clauses, an error is signaled rather than 1860not match any of the clauses, an error is signaled rather than
1860simply returning @code{nil}. 1861simply returning @code{nil}.
1861@end defspec 1862@end defspec
1862 1863
1863@defspec typecase keyform clause@dots{} 1864@defspec cl-typecase keyform clause@dots{}
1864This macro is a version of @code{case} that checks for types 1865This macro is a version of @code{cl-case} that checks for types
1865rather than values. Each @var{clause} is of the form 1866rather than values. Each @var{clause} is of the form
1866@samp{(@var{type} @var{body}...)}. @xref{Type Predicates}, 1867@samp{(@var{type} @var{body}...)}. @xref{Type Predicates},
1867for a description of type specifiers. For example, 1868for a description of type specifiers. For example,
1868 1869
1869@example 1870@example
1870(typecase x 1871(cl-typecase x
1871 (integer (munch-integer x)) 1872 (integer (munch-integer x))
1872 (float (munch-float x)) 1873 (float (munch-float x))
1873 (string (munch-integer (string-to-int x))) 1874 (string (munch-integer (string-to-int x)))
@@ -1879,8 +1880,8 @@ The type specifier @code{t} matches any type of object; the word
1879several types, use an @code{(or ...)} type specifier. 1880several types, use an @code{(or ...)} type specifier.
1880@end defspec 1881@end defspec
1881 1882
1882@defspec etypecase keyform clause@dots{} 1883@defspec cl-etypecase keyform clause@dots{}
1883This macro is just like @code{typecase}, except that if the key does 1884This macro is just like @code{cl-typecase}, except that if the key does
1884not match any of the clauses, an error is signaled rather than 1885not match any of the clauses, an error is signaled rather than
1885simply returning @code{nil}. 1886simply returning @code{nil}.
1886@end defspec 1887@end defspec
@@ -1891,26 +1892,26 @@ simply returning @code{nil}.
1891@noindent 1892@noindent
1892Common Lisp @dfn{blocks} provide a non-local exit mechanism very 1893Common Lisp @dfn{blocks} provide a non-local exit mechanism very
1893similar to @code{catch} and @code{throw}, but lexically rather than 1894similar to @code{catch} and @code{throw}, but lexically rather than
1894dynamically scoped. This package actually implements @code{block} 1895dynamically scoped. This package actually implements @code{cl-block}
1895in terms of @code{catch}; however, the lexical scoping allows the 1896in terms of @code{catch}; however, the lexical scoping allows the
1896optimizing byte-compiler to omit the costly @code{catch} step if the 1897optimizing byte-compiler to omit the costly @code{catch} step if the
1897body of the block does not actually @code{return-from} the block. 1898body of the block does not actually @code{cl-return-from} the block.
1898 1899
1899@defspec block name forms@dots{} 1900@defspec cl-block name forms@dots{}
1900The @var{forms} are evaluated as if by a @code{progn}. However, 1901The @var{forms} are evaluated as if by a @code{progn}. However,
1901if any of the @var{forms} execute @code{(return-from @var{name})}, 1902if any of the @var{forms} execute @code{(cl-return-from @var{name})},
1902they will jump out and return directly from the @code{block} form. 1903they will jump out and return directly from the @code{cl-block} form.
1903The @code{block} returns the result of the last @var{form} unless 1904The @code{cl-block} returns the result of the last @var{form} unless
1904a @code{return-from} occurs. 1905a @code{cl-return-from} occurs.
1905 1906
1906The @code{block}/@code{return-from} mechanism is quite similar to 1907The @code{cl-block}/@code{cl-return-from} mechanism is quite similar to
1907the @code{catch}/@code{throw} mechanism. The main differences are 1908the @code{catch}/@code{throw} mechanism. The main differences are
1908that block @var{name}s are unevaluated symbols, rather than forms 1909that block @var{name}s are unevaluated symbols, rather than forms
1909(such as quoted symbols) which evaluate to a tag at run-time; and 1910(such as quoted symbols) which evaluate to a tag at run-time; and
1910also that blocks are lexically scoped whereas @code{catch}/@code{throw} 1911also that blocks are lexically scoped whereas @code{catch}/@code{throw}
1911are dynamically scoped. This means that functions called from the 1912are dynamically scoped. This means that functions called from the
1912body of a @code{catch} can also @code{throw} to the @code{catch}, 1913body of a @code{catch} can also @code{throw} to the @code{catch},
1913but the @code{return-from} referring to a block name must appear 1914but the @code{cl-return-from} referring to a block name must appear
1914physically within the @var{forms} that make up the body of the block. 1915physically within the @var{forms} that make up the body of the block.
1915They may not appear within other called functions, although they may 1916They may not appear within other called functions, although they may
1916appear within macro expansions or @code{lambda}s in the body. Block 1917appear within macro expansions or @code{lambda}s in the body. Block
@@ -1919,11 +1920,11 @@ names and @code{catch} names form independent name-spaces.
1919In true Common Lisp, @code{defun} and @code{defmacro} surround 1920In true Common Lisp, @code{defun} and @code{defmacro} surround
1920the function or expander bodies with implicit blocks with the 1921the function or expander bodies with implicit blocks with the
1921same name as the function or macro. This does not occur in Emacs 1922same name as the function or macro. This does not occur in Emacs
1922Lisp, but this package provides @code{defun*} and @code{defmacro*} 1923Lisp, but this package provides @code{cl-defun} and @code{cl-defmacro}
1923forms which do create the implicit block. 1924forms which do create the implicit block.
1924 1925
1925The Common Lisp looping constructs defined by this package, 1926The Common Lisp looping constructs defined by this package,
1926such as @code{loop} and @code{dolist}, also create implicit blocks 1927such as @code{cl-loop} and @code{cl-dolist}, also create implicit blocks
1927just as in Common Lisp. 1928just as in Common Lisp.
1928 1929
1929Because they are implemented in terms of Emacs Lisp @code{catch} 1930Because they are implemented in terms of Emacs Lisp @code{catch}
@@ -1931,22 +1932,22 @@ and @code{throw}, blocks have the same overhead as actual
1931@code{catch} constructs (roughly two function calls). However, 1932@code{catch} constructs (roughly two function calls). However,
1932the optimizing byte compiler will optimize away the @code{catch} 1933the optimizing byte compiler will optimize away the @code{catch}
1933if the block does 1934if the block does
1934not in fact contain any @code{return} or @code{return-from} calls 1935not in fact contain any @code{cl-return} or @code{cl-return-from} calls
1935that jump to it. This means that @code{do} loops and @code{defun*} 1936that jump to it. This means that @code{cl-do} loops and @code{cl-defun}
1936functions which don't use @code{return} don't pay the overhead to 1937functions which don't use @code{cl-return} don't pay the overhead to
1937support it. 1938support it.
1938@end defspec 1939@end defspec
1939 1940
1940@defspec return-from name [result] 1941@defspec cl-return-from name [result]
1941This macro returns from the block named @var{name}, which must be 1942This macro returns from the block named @var{name}, which must be
1942an (unevaluated) symbol. If a @var{result} form is specified, it 1943an (unevaluated) symbol. If a @var{result} form is specified, it
1943is evaluated to produce the result returned from the @code{block}. 1944is evaluated to produce the result returned from the @code{block}.
1944Otherwise, @code{nil} is returned. 1945Otherwise, @code{nil} is returned.
1945@end defspec 1946@end defspec
1946 1947
1947@defspec return [result] 1948@defspec cl-return [result]
1948This macro is exactly like @code{(return-from nil @var{result})}. 1949This macro is exactly like @code{(cl-return-from nil @var{result})}.
1949Common Lisp loops like @code{do} and @code{dolist} implicitly enclose 1950Common Lisp loops like @code{cl-do} and @code{cl-dolist} implicitly enclose
1950themselves in @code{nil} blocks. 1951themselves in @code{nil} blocks.
1951@end defspec 1952@end defspec
1952 1953
@@ -1958,27 +1959,27 @@ The macros described here provide more sophisticated, high-level
1958looping constructs to complement Emacs Lisp's basic @code{while} 1959looping constructs to complement Emacs Lisp's basic @code{while}
1959loop. 1960loop.
1960 1961
1961@defspec loop forms@dots{} 1962@defspec cl-loop forms@dots{}
1962The @code{CL} package supports both the simple, old-style meaning of 1963The @code{CL} package supports both the simple, old-style meaning of
1963@code{loop} and the extremely powerful and flexible feature known as 1964@code{loop} and the extremely powerful and flexible feature known as
1964the @dfn{Loop Facility} or @dfn{Loop Macro}. This more advanced 1965the @dfn{Loop Facility} or @dfn{Loop Macro}. This more advanced
1965facility is discussed in the following section; @pxref{Loop Facility}. 1966facility is discussed in the following section; @pxref{Loop Facility}.
1966The simple form of @code{loop} is described here. 1967The simple form of @code{loop} is described here.
1967 1968
1968If @code{loop} is followed by zero or more Lisp expressions, 1969If @code{cl-loop} is followed by zero or more Lisp expressions,
1969then @code{(loop @var{exprs}@dots{})} simply creates an infinite 1970then @code{(cl-loop @var{exprs}@dots{})} simply creates an infinite
1970loop executing the expressions over and over. The loop is 1971loop executing the expressions over and over. The loop is
1971enclosed in an implicit @code{nil} block. Thus, 1972enclosed in an implicit @code{nil} block. Thus,
1972 1973
1973@example 1974@example
1974(loop (foo) (if (no-more) (return 72)) (bar)) 1975(cl-loop (foo) (if (no-more) (return 72)) (bar))
1975@end example 1976@end example
1976 1977
1977@noindent 1978@noindent
1978is exactly equivalent to 1979is exactly equivalent to
1979 1980
1980@example 1981@example
1981(block nil (while t (foo) (if (no-more) (return 72)) (bar))) 1982(cl-block nil (while t (foo) (if (no-more) (return 72)) (bar)))
1982@end example 1983@end example
1983 1984
1984If any of the expressions are plain symbols, the loop is instead 1985If any of the expressions are plain symbols, the loop is instead
@@ -1988,7 +1989,7 @@ in the above notation would simply access and throw away the
1988value of a variable.) 1989value of a variable.)
1989@end defspec 1990@end defspec
1990 1991
1991@defspec do (spec@dots{}) (end-test [result@dots{}]) forms@dots{} 1992@defspec cl-do (spec@dots{}) (end-test [result@dots{}]) forms@dots{}
1992This macro creates a general iterative loop. Each @var{spec} is 1993This macro creates a general iterative loop. Each @var{spec} is
1993of the form 1994of the form
1994 1995
@@ -2006,8 +2007,8 @@ begins. Once the @var{end-test} becomes true, the @var{result}
2006forms are evaluated (with the @var{var}s still bound to their 2007forms are evaluated (with the @var{var}s still bound to their
2007values) to produce the result returned by @code{do}. 2008values) to produce the result returned by @code{do}.
2008 2009
2009The entire @code{do} loop is enclosed in an implicit @code{nil} 2010The entire @code{cl-do} loop is enclosed in an implicit @code{nil}
2010block, so that you can use @code{(return)} to break out of the 2011block, so that you can use @code{(cl-return)} to break out of the
2011loop at any time. 2012loop at any time.
2012 2013
2013If there are no @var{result} forms, the loop returns @code{nil}. 2014If there are no @var{result} forms, the loop returns @code{nil}.
@@ -2023,21 +2024,21 @@ in place of @samp{(@var{var})}, again following the analogy with
2023This example (from Steele) illustrates a loop which applies the 2024This example (from Steele) illustrates a loop which applies the
2024function @code{f} to successive pairs of values from the lists 2025function @code{f} to successive pairs of values from the lists
2025@code{foo} and @code{bar}; it is equivalent to the call 2026@code{foo} and @code{bar}; it is equivalent to the call
2026@code{(mapcar* 'f foo bar)}. Note that this loop has no body 2027@code{(cl-mapcar 'f foo bar)}. Note that this loop has no body
2027@var{forms} at all, performing all its work as side effects of 2028@var{forms} at all, performing all its work as side effects of
2028the rest of the loop. 2029the rest of the loop.
2029 2030
2030@example 2031@example
2031(do ((x foo (cdr x)) 2032(cl-do ((x foo (cdr x))
2032 (y bar (cdr y)) 2033 (y bar (cdr y))
2033 (z nil (cons (f (car x) (car y)) z))) 2034 (z nil (cons (f (car x) (car y)) z)))
2034 ((or (null x) (null y)) 2035 ((or (null x) (null y))
2035 (nreverse z))) 2036 (nreverse z)))
2036@end example 2037@end example
2037@end defspec 2038@end defspec
2038 2039
2039@defspec do* (spec@dots{}) (end-test [result@dots{}]) forms@dots{} 2040@defspec cl-do* (spec@dots{}) (end-test [result@dots{}]) forms@dots{}
2040This is to @code{do} what @code{let*} is to @code{let}. In 2041This is to @code{cl-do} what @code{let*} is to @code{let}. In
2041particular, the initial values are bound as if by @code{let*} 2042particular, the initial values are bound as if by @code{let*}
2042rather than @code{let}, and the steps are assigned as if by 2043rather than @code{let}, and the steps are assigned as if by
2043@code{setq} rather than @code{cl-psetq}. 2044@code{setq} rather than @code{cl-psetq}.
@@ -2045,18 +2046,18 @@ rather than @code{let}, and the steps are assigned as if by
2045Here is another way to write the above loop: 2046Here is another way to write the above loop:
2046 2047
2047@example 2048@example
2048(do* ((xp foo (cdr xp)) 2049(cl-do* ((xp foo (cdr xp))
2049 (yp bar (cdr yp)) 2050 (yp bar (cdr yp))
2050 (x (car xp) (car xp)) 2051 (x (car xp) (car xp))
2051 (y (car yp) (car yp)) 2052 (y (car yp) (car yp))
2052 z) 2053 z)
2053 ((or (null xp) (null yp)) 2054 ((or (null xp) (null yp))
2054 (nreverse z)) 2055 (nreverse z))
2055 (push (f x y) z)) 2056 (push (f x y) z))
2056@end example 2057@end example
2057@end defspec 2058@end defspec
2058 2059
2059@defspec dolist (var list [result]) forms@dots{} 2060@defspec cl-dolist (var list [result]) forms@dots{}
2060This is a more specialized loop which iterates across the elements 2061This is a more specialized loop which iterates across the elements
2061of a list. @var{list} should evaluate to a list; the body @var{forms} 2062of a list. @var{list} should evaluate to a list; the body @var{forms}
2062are executed with @var{var} bound to each element of the list in 2063are executed with @var{var} bound to each element of the list in
@@ -2066,7 +2067,7 @@ the loop. Unlike with Emacs's built in @code{dolist}, the loop is
2066surrounded by an implicit @code{nil} block. 2067surrounded by an implicit @code{nil} block.
2067@end defspec 2068@end defspec
2068 2069
2069@defspec dotimes (var count [result]) forms@dots{} 2070@defspec cl-dotimes (var count [result]) forms@dots{}
2070This is a more specialized loop which iterates a specified number 2071This is a more specialized loop which iterates a specified number
2071of times. The body is executed with @var{var} bound to the integers 2072of times. The body is executed with @var{var} bound to the integers
2072from zero (inclusive) to @var{count} (exclusive), in turn. Then 2073from zero (inclusive) to @var{count} (exclusive), in turn. Then
@@ -2076,7 +2077,7 @@ to get the return value for the loop form. Unlike with Emacs's built in
2076@code{dolist}, the loop is surrounded by an implicit @code{nil} block. 2077@code{dolist}, the loop is surrounded by an implicit @code{nil} block.
2077@end defspec 2078@end defspec
2078 2079
2079@defspec do-symbols (var [obarray [result]]) forms@dots{} 2080@defspec cl-do-symbols (var [obarray [result]]) forms@dots{}
2080This loop iterates over all interned symbols. If @var{obarray} 2081This loop iterates over all interned symbols. If @var{obarray}
2081is specified and is not @code{nil}, it loops over all symbols in 2082is specified and is not @code{nil}, it loops over all symbols in
2082that obarray. For each symbol, the body @var{forms} are evaluated 2083that obarray. For each symbol, the body @var{forms} are evaluated
@@ -2086,8 +2087,8 @@ is evaluated (with @var{var} bound to @code{nil}) to get the return
2086value. The loop is surrounded by an implicit @code{nil} block. 2087value. The loop is surrounded by an implicit @code{nil} block.
2087@end defspec 2088@end defspec
2088 2089
2089@defspec do-all-symbols (var [result]) forms@dots{} 2090@defspec cl-do-all-symbols (var [result]) forms@dots{}
2090This is identical to @code{do-symbols} except that the @var{obarray} 2091This is identical to @code{cl-do-symbols} except that the @var{obarray}
2091argument is omitted; it always iterates over the default obarray. 2092argument is omitted; it always iterates over the default obarray.
2092@end defspec 2093@end defspec
2093 2094
@@ -2108,8 +2109,8 @@ construct called the ``Loop Facility'' or ``@code{loop} macro,''
2108with an easy-to-use but very powerful and expressive syntax. 2109with an easy-to-use but very powerful and expressive syntax.
2109 2110
2110@menu 2111@menu
2111* Loop Basics:: @code{loop} macro, basic clause structure. 2112* Loop Basics:: @code{cl-loop} macro, basic clause structure.
2112* Loop Examples:: Working examples of @code{loop} macro. 2113* Loop Examples:: Working examples of @code{cl-loop} macro.
2113* For Clauses:: Clauses introduced by @code{for} or @code{as}. 2114* For Clauses:: Clauses introduced by @code{for} or @code{as}.
2114* Iteration Clauses:: @code{repeat}, @code{while}, @code{thereis}, etc. 2115* Iteration Clauses:: @code{repeat}, @code{while}, @code{thereis}, etc.
2115* Accumulation Clauses:: @code{collect}, @code{sum}, @code{maximize}, etc. 2116* Accumulation Clauses:: @code{collect}, @code{sum}, @code{maximize}, etc.
@@ -2120,19 +2121,19 @@ with an easy-to-use but very powerful and expressive syntax.
2120@subsection Loop Basics 2121@subsection Loop Basics
2121 2122
2122@noindent 2123@noindent
2123The @code{loop} macro essentially creates a mini-language within 2124The @code{cl-loop} macro essentially creates a mini-language within
2124Lisp that is specially tailored for describing loops. While this 2125Lisp that is specially tailored for describing loops. While this
2125language is a little strange-looking by the standards of regular Lisp, 2126language is a little strange-looking by the standards of regular Lisp,
2126it turns out to be very easy to learn and well-suited to its purpose. 2127it turns out to be very easy to learn and well-suited to its purpose.
2127 2128
2128Since @code{loop} is a macro, all parsing of the loop language 2129Since @code{cl-loop} is a macro, all parsing of the loop language
2129takes place at byte-compile time; compiled @code{loop}s are just 2130takes place at byte-compile time; compiled @code{cl-loop}s are just
2130as efficient as the equivalent @code{while} loops written longhand. 2131as efficient as the equivalent @code{while} loops written longhand.
2131 2132
2132@defspec loop clauses@dots{} 2133@defspec cl-loop clauses@dots{}
2133A loop construct consists of a series of @var{clause}s, each 2134A loop construct consists of a series of @var{clause}s, each
2134introduced by a symbol like @code{for} or @code{do}. Clauses 2135introduced by a symbol like @code{for} or @code{do}. Clauses
2135are simply strung together in the argument list of @code{loop}, 2136are simply strung together in the argument list of @code{cl-loop},
2136with minimal extra parentheses. The various types of clauses 2137with minimal extra parentheses. The various types of clauses
2137specify initializations, such as the binding of temporary 2138specify initializations, such as the binding of temporary
2138variables, actions to be taken in the loop, stepping actions, 2139variables, actions to be taken in the loop, stepping actions,
@@ -2142,9 +2143,9 @@ Common Lisp specifies a certain general order of clauses in a
2142loop: 2143loop:
2143 2144
2144@example 2145@example
2145(loop @var{name-clause} 2146(cl-loop @var{name-clause}
2146 @var{var-clauses}@dots{} 2147 @var{var-clauses}@dots{}
2147 @var{action-clauses}@dots{}) 2148 @var{action-clauses}@dots{})
2148@end example 2149@end example
2149 2150
2150The @var{name-clause} optionally gives a name to the implicit 2151The @var{name-clause} optionally gives a name to the implicit
@@ -2155,7 +2156,7 @@ be modified or iterated throughout the course of the loop. The
2155@var{action-clauses} are things to be done during the loop, such 2156@var{action-clauses} are things to be done during the loop, such
2156as computing, collecting, and returning values. 2157as computing, collecting, and returning values.
2157 2158
2158The Emacs version of the @code{loop} macro is less restrictive about 2159The Emacs version of the @code{cl-loop} macro is less restrictive about
2159the order of clauses, but things will behave most predictably if 2160the order of clauses, but things will behave most predictably if
2160you put the variable-binding clauses @code{with}, @code{for}, and 2161you put the variable-binding clauses @code{with}, @code{for}, and
2161@code{repeat} before the action clauses. As in Common Lisp, 2162@code{repeat} before the action clauses. As in Common Lisp,
@@ -2180,25 +2181,25 @@ for additional discussion and examples of the @code{loop} macro.
2180 2181
2181@noindent 2182@noindent
2182Before listing the full set of clauses that are allowed, let's 2183Before listing the full set of clauses that are allowed, let's
2183look at a few example loops just to get a feel for the @code{loop} 2184look at a few example loops just to get a feel for the @code{cl-loop}
2184language. 2185language.
2185 2186
2186@example 2187@example
2187(loop for buf in (buffer-list) 2188(cl-loop for buf in (buffer-list)
2188 collect (buffer-file-name buf)) 2189 collect (buffer-file-name buf))
2189@end example 2190@end example
2190 2191
2191@noindent 2192@noindent
2192This loop iterates over all Emacs buffers, using the list 2193This loop iterates over all Emacs buffers, using the list
2193returned by @code{buffer-list}. For each buffer @code{buf}, 2194returned by @code{buffer-list}. For each buffer @code{buf},
2194it calls @code{buffer-file-name} and collects the results into 2195it calls @code{buffer-file-name} and collects the results into
2195a list, which is then returned from the @code{loop} construct. 2196a list, which is then returned from the @code{cl-loop} construct.
2196The result is a list of the file names of all the buffers in 2197The result is a list of the file names of all the buffers in
2197Emacs's memory. The words @code{for}, @code{in}, and @code{collect} 2198Emacs's memory. The words @code{for}, @code{in}, and @code{collect}
2198are reserved words in the @code{loop} language. 2199are reserved words in the @code{cl-loop} language.
2199 2200
2200@example 2201@example
2201(loop repeat 20 do (insert "Yowsa\n")) 2202(cl-loop repeat 20 do (insert "Yowsa\n"))
2202@end example 2203@end example
2203 2204
2204@noindent 2205@noindent
@@ -2206,7 +2207,7 @@ This loop inserts the phrase ``Yowsa'' twenty times in the
2206current buffer. 2207current buffer.
2207 2208
2208@example 2209@example
2209(loop until (eobp) do (munch-line) (forward-line 1)) 2210(cl-loop until (eobp) do (munch-line) (forward-line 1))
2210@end example 2211@end example
2211 2212
2212@noindent 2213@noindent
@@ -2215,7 +2216,7 @@ of the buffer. If point is already at the end of the buffer,
2215the loop exits immediately. 2216the loop exits immediately.
2216 2217
2217@example 2218@example
2218(loop do (munch-line) until (eobp) do (forward-line 1)) 2219(cl-loop do (munch-line) until (eobp) do (forward-line 1))
2219@end example 2220@end example
2220 2221
2221@noindent 2222@noindent
@@ -2223,10 +2224,10 @@ This loop is similar to the above one, except that @code{munch-line}
2223is always called at least once. 2224is always called at least once.
2224 2225
2225@example 2226@example
2226(loop for x from 1 to 100 2227(cl-loop for x from 1 to 100
2227 for y = (* x x) 2228 for y = (* x x)
2228 until (>= y 729) 2229 until (>= y 729)
2229 finally return (list x (= y 729))) 2230 finally return (list x (= y 729)))
2230@end example 2231@end example
2231 2232
2232@noindent 2233@noindent
@@ -2246,7 +2247,7 @@ Note that even though this loop contains three clauses (two
2246@code{for}s and an @code{until}) that would have been enough to 2247@code{for}s and an @code{until}) that would have been enough to
2247define loops all by themselves, it still creates a single loop 2248define loops all by themselves, it still creates a single loop
2248rather than some sort of triple-nested loop. You must explicitly 2249rather than some sort of triple-nested loop. You must explicitly
2249nest your @code{loop} constructs if you want nested loops. 2250nest your @code{cl-loop} constructs if you want nested loops.
2250 2251
2251@node For Clauses 2252@node For Clauses
2252@subsection For Clauses 2253@subsection For Clauses
@@ -2272,7 +2273,7 @@ The variable is bound around the loop as if by @code{let}:
2272 2273
2273@example 2274@example
2274(setq i 'happy) 2275(setq i 'happy)
2275(loop for i from 1 to 10 do (do-something-with i)) 2276(cl-loop for i from 1 to 10 do (do-something-with i))
2276i 2277i
2277 @result{} happy 2278 @result{} happy
2278@end example 2279@end example
@@ -2302,10 +2303,10 @@ which are like @code{upto} and @code{downto} respectively except
2302that they are exclusive rather than inclusive limits: 2303that they are exclusive rather than inclusive limits:
2303 2304
2304@example 2305@example
2305(loop for x to 10 collect x) 2306(cl-loop for x to 10 collect x)
2306 @result{} (0 1 2 3 4 5 6 7 8 9 10) 2307 @result{} (0 1 2 3 4 5 6 7 8 9 10)
2307(loop for x below 10 collect x) 2308(cl-loop for x below 10 collect x)
2308 @result{} (0 1 2 3 4 5 6 7 8 9) 2309 @result{} (0 1 2 3 4 5 6 7 8 9)
2309@end example 2310@end example
2310 2311
2311The @code{by} value is always positive, even for downward-counting 2312The @code{by} value is always positive, even for downward-counting
@@ -2320,25 +2321,25 @@ is used to traverse the list instead of @code{cdr}; it must be a
2320function taking one argument. For example: 2321function taking one argument. For example:
2321 2322
2322@example 2323@example
2323(loop for x in '(1 2 3 4 5 6) collect (* x x)) 2324(cl-loop for x in '(1 2 3 4 5 6) collect (* x x))
2324 @result{} (1 4 9 16 25 36) 2325 @result{} (1 4 9 16 25 36)
2325(loop for x in '(1 2 3 4 5 6) by 'cddr collect (* x x)) 2326(cl-loop for x in '(1 2 3 4 5 6) by 'cddr collect (* x x))
2326 @result{} (1 9 25) 2327 @result{} (1 9 25)
2327@end example 2328@end example
2328 2329
2329@item for @var{var} on @var{list} by @var{function} 2330@item for @var{var} on @var{list} by @var{function}
2330This clause iterates @var{var} over all the cons cells of @var{list}. 2331This clause iterates @var{var} over all the cons cells of @var{list}.
2331 2332
2332@example 2333@example
2333(loop for x on '(1 2 3 4) collect x) 2334(cl-loop for x on '(1 2 3 4) collect x)
2334 @result{} ((1 2 3 4) (2 3 4) (3 4) (4)) 2335 @result{} ((1 2 3 4) (2 3 4) (3 4) (4))
2335@end example 2336@end example
2336 2337
2337With @code{by}, there is no real reason that the @code{on} expression 2338With @code{by}, there is no real reason that the @code{on} expression
2338must be a list. For example: 2339must be a list. For example:
2339 2340
2340@example 2341@example
2341(loop for x on first-animal by 'next-animal collect x) 2342(cl-loop for x on first-animal by 'next-animal collect x)
2342@end example 2343@end example
2343 2344
2344@noindent 2345@noindent
@@ -2352,7 +2353,7 @@ a @code{setf}-able ``reference'' onto the elements of the list
2352rather than just a temporary variable. For example, 2353rather than just a temporary variable. For example,
2353 2354
2354@example 2355@example
2355(loop for x in-ref my-list do (incf x)) 2356(cl-loop for x in-ref my-list do (cl-incf x))
2356@end example 2357@end example
2357 2358
2358@noindent 2359@noindent
@@ -2364,8 +2365,8 @@ This clause iterates @var{var} over all the elements of @var{array},
2364which may be a vector or a string. 2365which may be a vector or a string.
2365 2366
2366@example 2367@example
2367(loop for x across "aeiou" 2368(cl-loop for x across "aeiou"
2368 do (use-vowel (char-to-string x))) 2369 do (use-vowel (char-to-string x)))
2369@end example 2370@end example
2370 2371
2371@item for @var{var} across-ref @var{array} 2372@item for @var{var} across-ref @var{array}
@@ -2397,10 +2398,10 @@ an unspecified order.
2397As an example, 2398As an example,
2398 2399
2399@example 2400@example
2400(loop for sym being the symbols 2401(cl-loop for sym being the symbols
2401 when (fboundp sym) 2402 when (fboundp sym)
2402 when (string-match "^map" (symbol-name sym)) 2403 when (string-match "^map" (symbol-name sym))
2403 collect sym) 2404 collect sym)
2404@end example 2405@end example
2405 2406
2406@noindent 2407@noindent
@@ -2411,7 +2412,7 @@ are also recognized but are equivalent to @code{symbols} in Emacs Lisp.
2411 2412
2412Due to a minor implementation restriction, it will not work to have 2413Due to a minor implementation restriction, it will not work to have
2413more than one @code{for} clause iterating over symbols, hash tables, 2414more than one @code{for} clause iterating over symbols, hash tables,
2414keymaps, overlays, or intervals in a given @code{loop}. Fortunately, 2415keymaps, overlays, or intervals in a given @code{cl-loop}. Fortunately,
2415it would rarely if ever be useful to do so. It @emph{is} valid to mix 2416it would rarely if ever be useful to do so. It @emph{is} valid to mix
2416one of these types of clauses with other clauses like @code{for ... to} 2417one of these types of clauses with other clauses like @code{for ... to}
2417or @code{while}. 2418or @code{while}.
@@ -2423,10 +2424,10 @@ This clause iterates over the entries in @var{hash-table} with
2423a second variable to the opposite part. 2424a second variable to the opposite part.
2424 2425
2425@example 2426@example
2426(loop for k being the hash-keys of h 2427(cl-loop for k being the hash-keys of h
2427 using (hash-values v) 2428 using (hash-values v)
2428 do 2429 do
2429 (message "key %S -> value %S" k v)) 2430 (message "key %S -> value %S" k v))
2430@end example 2431@end example
2431 2432
2432@item for @var{var} being the key-codes of @var{keymap} 2433@item for @var{var} being the key-codes of @var{keymap}
@@ -2438,10 +2439,10 @@ A @code{using} clause can access both the codes and the bindings
2438together. 2439together.
2439 2440
2440@example 2441@example
2441(loop for c being the key-codes of (current-local-map) 2442(cl-loop for c being the key-codes of (current-local-map)
2442 using (key-bindings b) 2443 using (key-bindings b)
2443 do 2444 do
2444 (message "key %S -> binding %S" c b)) 2445 (message "key %S -> binding %S" c b))
2445@end example 2446@end example
2446 2447
2447 2448
@@ -2497,8 +2498,8 @@ and successive iterations it will be set by evaluating @var{expr2}
2497these two loops are effectively the same: 2498these two loops are effectively the same:
2498 2499
2499@example 2500@example
2500(loop for x on my-list by 'cddr do ...) 2501(cl-loop for x on my-list by 'cddr do ...)
2501(loop for x = my-list then (cddr x) while x do ...) 2502(cl-loop for x = my-list then (cddr x) while x do ...)
2502@end example 2503@end example
2503 2504
2504Note that this type of @code{for} clause does not imply any sort 2505Note that this type of @code{for} clause does not imply any sort
@@ -2509,7 +2510,7 @@ If you omit the @code{then} term, @var{expr1} is used both for
2509the initial setting and for successive settings: 2510the initial setting and for successive settings:
2510 2511
2511@example 2512@example
2512(loop for x = (random) when (> x 0) return x) 2513(cl-loop for x = (random) when (> x 0) return x)
2513@end example 2514@end example
2514 2515
2515@noindent 2516@noindent
@@ -2524,10 +2525,10 @@ in which case they are processed in parallel (as if by @code{let}
2524and @code{cl-psetq}). 2525and @code{cl-psetq}).
2525 2526
2526@example 2527@example
2527(loop for x below 5 for y = nil then x collect (list x y)) 2528(cl-loop for x below 5 for y = nil then x collect (list x y))
2528 @result{} ((0 nil) (1 1) (2 2) (3 3) (4 4)) 2529 @result{} ((0 nil) (1 1) (2 2) (3 3) (4 4))
2529(loop for x below 5 and y = nil then x collect (list x y)) 2530(cl-loop for x below 5 and y = nil then x collect (list x y))
2530 @result{} ((0 nil) (1 0) (2 1) (3 2) (4 3)) 2531 @result{} ((0 nil) (1 0) (2 1) (3 2) (4 3))
2531@end example 2532@end example
2532 2533
2533@noindent 2534@noindent
@@ -2537,7 +2538,7 @@ that was just set by the previous clause; in the second loop,
2537based on the value of @code{x} left over from the previous time 2538based on the value of @code{x} left over from the previous time
2538through the loop. 2539through the loop.
2539 2540
2540Another feature of the @code{loop} macro is @dfn{destructuring}, 2541Another feature of the @code{cl-loop} macro is @dfn{destructuring},
2541similar in concept to the destructuring provided by @code{defmacro}. 2542similar in concept to the destructuring provided by @code{defmacro}.
2542The @var{var} part of any @code{for} clause can be given as a list 2543The @var{var} part of any @code{for} clause can be given as a list
2543of variables instead of a single variable. The values produced 2544of variables instead of a single variable. The values produced
@@ -2545,8 +2546,8 @@ during loop execution must be lists; the values in the lists are
2545stored in the corresponding variables. 2546stored in the corresponding variables.
2546 2547
2547@example 2548@example
2548(loop for (x y) in '((2 3) (4 5) (6 7)) collect (+ x y)) 2549(cl-loop for (x y) in '((2 3) (4 5) (6 7)) collect (+ x y))
2549 @result{} (5 9 13) 2550 @result{} (5 9 13)
2550@end example 2551@end example
2551 2552
2552In loop destructuring, if there are more values than variables 2553In loop destructuring, if there are more values than variables
@@ -2558,9 +2559,9 @@ lists of variables like @code{(x . y)} are allowed, so for example
2558to process an alist 2559to process an alist
2559 2560
2560@example 2561@example
2561(loop for (key . value) in '((a . 1) (b . 2)) 2562(cl-loop for (key . value) in '((a . 1) (b . 2))
2562 collect value) 2563 collect value)
2563 @result{} (1 2) 2564 @result{} (1 2)
2564@end example 2565@end example
2565 2566
2566@node Iteration Clauses 2567@node Iteration Clauses
@@ -2577,8 +2578,8 @@ This clause simply counts up to the specified number using an
2577internal temporary variable. The loops 2578internal temporary variable. The loops
2578 2579
2579@example 2580@example
2580(loop repeat (1+ n) do ...) 2581(cl-loop repeat (1+ n) do ...)
2581(loop for temp to n do ...) 2582(cl-loop for temp to n do ...)
2582@end example 2583@end example
2583 2584
2584@noindent 2585@noindent
@@ -2593,7 +2594,7 @@ that surrounds the second one:
2593 2594
2594@example 2595@example
2595(while @var{cond} @var{forms}@dots{}) 2596(while @var{cond} @var{forms}@dots{})
2596(loop while @var{cond} do @var{forms}@dots{}) 2597(cl-loop while @var{cond} do @var{forms}@dots{})
2597@end example 2598@end example
2598 2599
2599@item until @var{condition} 2600@item until @var{condition}
@@ -2607,7 +2608,7 @@ the @code{finally} clauses are not executed. If all the conditions
2607were non-@code{nil}, the loop returns @code{t}: 2608were non-@code{nil}, the loop returns @code{t}:
2608 2609
2609@example 2610@example
2610(if (loop for size in size-list always (> size 10)) 2611(if (cl-loop for size in size-list always (> size 10))
2611 (some-big-sizes) 2612 (some-big-sizes)
2612 (no-big-sizes)) 2613 (no-big-sizes))
2613@end example 2614@end example
@@ -2684,11 +2685,11 @@ It is valid for several accumulation clauses of the same type to
2684accumulate into the same place. From Steele: 2685accumulate into the same place. From Steele:
2685 2686
2686@example 2687@example
2687(loop for name in '(fred sue alice joe june) 2688(cl-loop for name in '(fred sue alice joe june)
2688 for kids in '((bob ken) () () (kris sunshine) ()) 2689 for kids in '((bob ken) () () (kris sunshine) ())
2689 collect name 2690 collect name
2690 append kids) 2691 append kids)
2691 @result{} (fred bob ken sue alice joe kris sunshine june) 2692 @result{} (fred bob ken sue alice joe kris sunshine june)
2692@end example 2693@end example
2693 2694
2694@node Other Clauses 2695@node Other Clauses
@@ -2704,17 +2705,17 @@ otherwise leaves the variable alone during the loop. The following
2704loops are basically equivalent: 2705loops are basically equivalent:
2705 2706
2706@example 2707@example
2707(loop with x = 17 do ...) 2708(cl-loop with x = 17 do ...)
2708(let ((x 17)) (loop do ...)) 2709(let ((x 17)) (cl-loop do ...))
2709(loop for x = 17 then x do ...) 2710(cl-loop for x = 17 then x do ...)
2710@end example 2711@end example
2711 2712
2712Naturally, the variable @var{var} might be used for some purpose 2713Naturally, the variable @var{var} might be used for some purpose
2713in the rest of the loop. For example: 2714in the rest of the loop. For example:
2714 2715
2715@example 2716@example
2716(loop for x in my-list with res = nil do (push x res) 2717(cl-loop for x in my-list with res = nil do (push x res)
2717 finally return res) 2718 finally return res)
2718@end example 2719@end example
2719 2720
2720This loop inserts the elements of @code{my-list} at the front of 2721This loop inserts the elements of @code{my-list} at the front of
@@ -2749,18 +2750,18 @@ by the name @code{it} in the ``then'' part. For example:
2749@example 2750@example
2750(setq funny-numbers '(6 13 -1)) 2751(setq funny-numbers '(6 13 -1))
2751 @result{} (6 13 -1) 2752 @result{} (6 13 -1)
2752(loop for x below 10 2753(cl-loop for x below 10
2753 if (oddp x) 2754 if (oddp x)
2754 collect x into odds 2755 collect x into odds
2755 and if (memq x funny-numbers) return (cdr it) end 2756 and if (memq x funny-numbers) return (cdr it) end
2756 else 2757 else
2757 collect x into evens 2758 collect x into evens
2758 finally return (vector odds evens)) 2759 finally return (vector odds evens))
2759 @result{} [(1 3 5 7 9) (0 2 4 6 8)] 2760 @result{} [(1 3 5 7 9) (0 2 4 6 8)]
2760(setq funny-numbers '(6 7 13 -1)) 2761(setq funny-numbers '(6 7 13 -1))
2761 @result{} (6 7 13 -1) 2762 @result{} (6 7 13 -1)
2762(loop <@r{same thing again}>) 2763(cl-loop <@r{same thing again}>)
2763 @result{} (13 -1) 2764 @result{} (13 -1)
2764@end example 2765@end example
2765 2766
2766Note the use of @code{and} to put two clauses into the ``then'' 2767Note the use of @code{and} to put two clauses into the ``then''
@@ -2828,7 +2829,7 @@ was named). The @code{return} clause is implemented a bit more
2828efficiently, though. 2829efficiently, though.
2829@end table 2830@end table
2830 2831
2831While there is no high-level way to add user extensions to @code{loop} 2832While there is no high-level way to add user extensions to @code{cl-loop}
2832(comparable to @code{defsetf} for @code{setf}, say), this package 2833(comparable to @code{defsetf} for @code{setf}, say), this package
2833does offer two properties called @code{cl-loop-handler} and 2834does offer two properties called @code{cl-loop-handler} and
2834@code{cl-loop-for-handler} which are functions to be called when 2835@code{cl-loop-for-handler} which are functions to be called when
@@ -2836,7 +2837,7 @@ a given symbol is encountered as a top-level loop clause or
2836@code{for} clause, respectively. Consult the source code in 2837@code{for} clause, respectively. Consult the source code in
2837file @file{cl-macs.el} for details. 2838file @file{cl-macs.el} for details.
2838 2839
2839This package's @code{loop} macro is compatible with that of Common 2840This package's @code{cl-loop} macro is compatible with that of Common
2840Lisp, except that a few features are not implemented: @code{loop-finish} 2841Lisp, except that a few features are not implemented: @code{loop-finish}
2841and data-type specifiers. Naturally, the @code{for} clauses which 2842and data-type specifiers. Naturally, the @code{for} clauses which
2842iterate over keymaps, overlays, intervals, frames, windows, and 2843iterate over keymaps, overlays, intervals, frames, windows, and
@@ -2851,14 +2852,14 @@ functions, by contrast, always return exactly one result. This
2851package makes no attempt to emulate Common Lisp multiple return 2852package makes no attempt to emulate Common Lisp multiple return
2852values; Emacs versions of Common Lisp functions that return more 2853values; Emacs versions of Common Lisp functions that return more
2853than one value either return just the first value (as in 2854than one value either return just the first value (as in
2854@code{compiler-macroexpand}) or return a list of values (as in 2855@code{cl-compiler-macroexpand}) or return a list of values (as in
2855@code{get-setf-method}). This package @emph{does} define placeholders 2856@code{get-setf-method}). This package @emph{does} define placeholders
2856for the Common Lisp functions that work with multiple values, but 2857for the Common Lisp functions that work with multiple values, but
2857in Emacs Lisp these functions simply operate on lists instead. 2858in Emacs Lisp these functions simply operate on lists instead.
2858The @code{values} form, for example, is a synonym for @code{list} 2859The @code{values} form, for example, is a synonym for @code{list}
2859in Emacs. 2860in Emacs.
2860 2861
2861@defspec multiple-value-bind (var@dots{}) values-form forms@dots{} 2862@defspec cl-multiple-value-bind (var@dots{}) values-form forms@dots{}
2862This form evaluates @var{values-form}, which must return a list of 2863This form evaluates @var{values-form}, which must return a list of
2863values. It then binds the @var{var}s to these respective values, 2864values. It then binds the @var{var}s to these respective values,
2864as if by @code{let}, and then executes the body @var{forms}. 2865as if by @code{let}, and then executes the body @var{forms}.
@@ -2867,18 +2868,18 @@ are bound to @code{nil}. If there are fewer @var{var}s than
2867values, the excess values are ignored. 2868values, the excess values are ignored.
2868@end defspec 2869@end defspec
2869 2870
2870@defspec multiple-value-setq (var@dots{}) form 2871@defspec cl-multiple-value-setq (var@dots{}) form
2871This form evaluates @var{form}, which must return a list of values. 2872This form evaluates @var{form}, which must return a list of values.
2872It then sets the @var{var}s to these respective values, as if by 2873It then sets the @var{var}s to these respective values, as if by
2873@code{setq}. Extra @var{var}s or values are treated the same as 2874@code{setq}. Extra @var{var}s or values are treated the same as
2874in @code{multiple-value-bind}. 2875in @code{cl-multiple-value-bind}.
2875@end defspec 2876@end defspec
2876 2877
2877The older Quiroz package attempted a more faithful (but still 2878The older Quiroz package attempted a more faithful (but still
2878imperfect) emulation of Common Lisp multiple values. The old 2879imperfect) emulation of Common Lisp multiple values. The old
2879method ``usually'' simulated true multiple values quite well, 2880method ``usually'' simulated true multiple values quite well,
2880but under certain circumstances would leave spurious return 2881but under certain circumstances would leave spurious return
2881values in memory where a later, unrelated @code{multiple-value-bind} 2882values in memory where a later, unrelated @code{cl-multiple-value-bind}
2882form would see them. 2883form would see them.
2883 2884
2884Since a perfect emulation is not feasible in Emacs Lisp, this 2885Since a perfect emulation is not feasible in Emacs Lisp, this
@@ -2897,7 +2898,7 @@ for @code{defmacro} due to technical difficulties.
2897Destructuring is made available to the user by way of the 2898Destructuring is made available to the user by way of the
2898following macro: 2899following macro:
2899 2900
2900@defspec destructuring-bind arglist expr forms@dots{} 2901@defspec cl-destructuring-bind arglist expr forms@dots{}
2901This macro expands to code which executes @var{forms}, with 2902This macro expands to code which executes @var{forms}, with
2902the variables in @var{arglist} bound to the list of values 2903the variables in @var{arglist} bound to the list of values
2903returned by @var{expr}. The @var{arglist} can include all 2904returned by @var{expr}. The @var{arglist} can include all
@@ -2908,11 +2909,11 @@ if @var{expr} returns a list of the wrong number of arguments
2908or with incorrect keyword arguments. 2909or with incorrect keyword arguments.
2909@end defspec 2910@end defspec
2910 2911
2911This package also includes the Common Lisp @code{define-compiler-macro} 2912This package also includes the Common Lisp @code{cl-define-compiler-macro}
2912facility, which allows you to define compile-time expansions and 2913facility, which allows you to define compile-time expansions and
2913optimizations for your functions. 2914optimizations for your functions.
2914 2915
2915@defspec define-compiler-macro name arglist forms@dots{} 2916@defspec cl-define-compiler-macro name arglist forms@dots{}
2916This form is similar to @code{defmacro}, except that it only expands 2917This form is similar to @code{defmacro}, except that it only expands
2917calls to @var{name} at compile-time; calls processed by the Lisp 2918calls to @var{name} at compile-time; calls processed by the Lisp
2918interpreter are not expanded, nor are they expanded by the 2919interpreter are not expanded, nor are they expanded by the
@@ -2930,25 +2931,25 @@ For example, here is a simplified version of a definition that
2930appears as a standard part of this package: 2931appears as a standard part of this package:
2931 2932
2932@example 2933@example
2933(define-compiler-macro member* (&whole form a list &rest keys) 2934(cl-define-compiler-macro cl-member (&whole form a list &rest keys)
2934 (if (and (null keys) 2935 (if (and (null keys)
2935 (eq (car-safe a) 'quote) 2936 (eq (car-safe a) 'quote)
2936 (not (floatp-safe (cadr a)))) 2937 (not (floatp-safe (cadr a))))
2937 (list 'memq a list) 2938 (list 'memq a list)
2938 form)) 2939 form))
2939@end example 2940@end example
2940 2941
2941@noindent 2942@noindent
2942This definition causes @code{(member* @var{a} @var{list})} to change 2943This definition causes @code{(cl-member @var{a} @var{list})} to change
2943to a call to the faster @code{memq} in the common case where @var{a} 2944to a call to the faster @code{memq} in the common case where @var{a}
2944is a non-floating-point constant; if @var{a} is anything else, or 2945is a non-floating-point constant; if @var{a} is anything else, or
2945if there are any keyword arguments in the call, then the original 2946if there are any keyword arguments in the call, then the original
2946@code{member*} call is left intact. (The actual compiler macro 2947@code{cl-member} call is left intact. (The actual compiler macro
2947for @code{member*} optimizes a number of other cases, including 2948for @code{cl-member} optimizes a number of other cases, including
2948common @code{:test} predicates.) 2949common @code{:test} predicates.)
2949@end defspec 2950@end defspec
2950 2951
2951@defun compiler-macroexpand form 2952@defun cl-compiler-macroexpand form
2952This function is analogous to @code{macroexpand}, except that it 2953This function is analogous to @code{macroexpand}, except that it
2953expands compiler macros rather than regular macros. It returns 2954expands compiler macros rather than regular macros. It returns
2954@var{form} unchanged if it is not a call to a function for which 2955@var{form} unchanged if it is not a call to a function for which
@@ -2958,8 +2959,8 @@ decided to punt by returning its @code{&whole} argument. Like
2958for which no further expansion is possible. 2959for which no further expansion is possible.
2959@end defun 2960@end defun
2960 2961
2961@xref{Macro Bindings}, for descriptions of the @code{macrolet} 2962@xref{Macro Bindings}, for descriptions of the @code{cl-macrolet}
2962and @code{symbol-macrolet} forms for making ``local'' macro 2963and @code{cl-symbol-macrolet} forms for making ``local'' macro
2963definitions. 2964definitions.
2964 2965
2965@node Declarations 2966@node Declarations
@@ -2971,8 +2972,8 @@ mechanism that allows you to give the compiler special hints
2971about the types of data that will be stored in particular variables, 2972about the types of data that will be stored in particular variables,
2972and about the ways those variables and functions will be used. This 2973and about the ways those variables and functions will be used. This
2973package defines versions of all the Common Lisp declaration forms: 2974package defines versions of all the Common Lisp declaration forms:
2974@code{declare}, @code{locally}, @code{proclaim}, @code{declaim}, 2975@code{cl-declare}, @code{cl-locally}, @code{cl-proclaim}, @code{cl-declaim},
2975and @code{the}. 2976and @code{cl-the}.
2976 2977
2977Most of the Common Lisp declarations are not currently useful in 2978Most of the Common Lisp declarations are not currently useful in
2978Emacs Lisp, as the byte-code system provides little opportunity 2979Emacs Lisp, as the byte-code system provides little opportunity
@@ -2982,53 +2983,53 @@ declarations are meaningful when the optimizing byte
2982compiler is being used, however. Under the earlier non-optimizing 2983compiler is being used, however. Under the earlier non-optimizing
2983compiler, these declarations will effectively be ignored. 2984compiler, these declarations will effectively be ignored.
2984 2985
2985@defun proclaim decl-spec 2986@defun cl-proclaim decl-spec
2986This function records a ``global'' declaration specified by 2987This function records a ``global'' declaration specified by
2987@var{decl-spec}. Since @code{proclaim} is a function, @var{decl-spec} 2988@var{decl-spec}. Since @code{cl-proclaim} is a function, @var{decl-spec}
2988is evaluated and thus should normally be quoted. 2989is evaluated and thus should normally be quoted.
2989@end defun 2990@end defun
2990 2991
2991@defspec declaim decl-specs@dots{} 2992@defspec cl-declaim decl-specs@dots{}
2992This macro is like @code{proclaim}, except that it takes any number 2993This macro is like @code{cl-proclaim}, except that it takes any number
2993of @var{decl-spec} arguments, and the arguments are unevaluated and 2994of @var{decl-spec} arguments, and the arguments are unevaluated and
2994unquoted. The @code{declaim} macro also puts an @code{(eval-when 2995unquoted. The @code{cl-declaim} macro also puts an @code{(cl-eval-when
2995(compile load eval) ...)} around the declarations so that they will 2996(compile load eval) ...)} around the declarations so that they will
2996be registered at compile-time as well as at run-time. (This is vital, 2997be registered at compile-time as well as at run-time. (This is vital,
2997since normally the declarations are meant to influence the way the 2998since normally the declarations are meant to influence the way the
2998compiler treats the rest of the file that contains the @code{declaim} 2999compiler treats the rest of the file that contains the @code{cl-declaim}
2999form.) 3000form.)
3000@end defspec 3001@end defspec
3001 3002
3002@defspec declare decl-specs@dots{} 3003@defspec cl-declare decl-specs@dots{}
3003This macro is used to make declarations within functions and other 3004This macro is used to make declarations within functions and other
3004code. Common Lisp allows declarations in various locations, generally 3005code. Common Lisp allows declarations in various locations, generally
3005at the beginning of any of the many ``implicit @code{progn}s'' 3006at the beginning of any of the many ``implicit @code{progn}s''
3006throughout Lisp syntax, such as function bodies, @code{let} bodies, 3007throughout Lisp syntax, such as function bodies, @code{let} bodies,
3007etc. Currently the only declaration understood by @code{declare} 3008etc. Currently the only declaration understood by @code{cl-declare}
3008is @code{special}. 3009is @code{special}.
3009@end defspec 3010@end defspec
3010 3011
3011@defspec locally declarations@dots{} forms@dots{} 3012@defspec cl-locally declarations@dots{} forms@dots{}
3012In this package, @code{locally} is no different from @code{progn}. 3013In this package, @code{cl-locally} is no different from @code{progn}.
3013@end defspec 3014@end defspec
3014 3015
3015@defspec the type form 3016@defspec cl-the type form
3016Type information provided by @code{the} is ignored in this package; 3017Type information provided by @code{cl-the} is ignored in this package;
3017in other words, @code{(the @var{type} @var{form})} is equivalent 3018in other words, @code{(cl-the @var{type} @var{form})} is equivalent
3018to @var{form}. Future versions of the optimizing byte-compiler may 3019to @var{form}. Future versions of the optimizing byte-compiler may
3019make use of this information. 3020make use of this information.
3020 3021
3021For example, @code{mapcar} can map over both lists and arrays. It is 3022For example, @code{mapcar} can map over both lists and arrays. It is
3022hard for the compiler to expand @code{mapcar} into an in-line loop 3023hard for the compiler to expand @code{mapcar} into an in-line loop
3023unless it knows whether the sequence will be a list or an array ahead 3024unless it knows whether the sequence will be a list or an array ahead
3024of time. With @code{(mapcar 'car (the vector foo))}, a future 3025of time. With @code{(mapcar 'car (cl-the vector foo))}, a future
3025compiler would have enough information to expand the loop in-line. 3026compiler would have enough information to expand the loop in-line.
3026For now, Emacs Lisp will treat the above code as exactly equivalent 3027For now, Emacs Lisp will treat the above code as exactly equivalent
3027to @code{(mapcar 'car foo)}. 3028to @code{(mapcar 'car foo)}.
3028@end defspec 3029@end defspec
3029 3030
3030Each @var{decl-spec} in a @code{proclaim}, @code{declaim}, or 3031Each @var{decl-spec} in a @code{cl-proclaim}, @code{cl-declaim}, or
3031@code{declare} should be a list beginning with a symbol that says 3032@code{cl-declare} should be a list beginning with a symbol that says
3032what kind of declaration it is. This package currently understands 3033what kind of declaration it is. This package currently understands
3033@code{special}, @code{inline}, @code{notinline}, @code{optimize}, 3034@code{special}, @code{inline}, @code{notinline}, @code{optimize},
3034and @code{warn} declarations. (The @code{warn} declaration is an 3035and @code{warn} declarations. (The @code{warn} declaration is an
@@ -3045,16 +3046,16 @@ bound in the body of the function. The compiler normally emits
3045warnings for such references, since they could be typographical 3046warnings for such references, since they could be typographical
3046errors for references to local variables. 3047errors for references to local variables.
3047 3048
3048The declaration @code{(declare (special @var{var1} @var{var2}))} is 3049The declaration @code{(cl-declare (special @var{var1} @var{var2}))} is
3049equivalent to @code{(defvar @var{var1}) (defvar @var{var2})} in the 3050equivalent to @code{(defvar @var{var1}) (defvar @var{var2})} in the
3050optimizing compiler, or to nothing at all in older compilers (which 3051optimizing compiler, or to nothing at all in older compilers (which
3051do not warn for non-local references). 3052do not warn for non-local references).
3052 3053
3053In top-level contexts, it is generally better to write 3054In top-level contexts, it is generally better to write
3054@code{(defvar @var{var})} than @code{(declaim (special @var{var}))}, 3055@code{(defvar @var{var})} than @code{(cl-declaim (special @var{var}))},
3055since @code{defvar} makes your intentions clearer. But the older 3056since @code{defvar} makes your intentions clearer. But the older
3056byte compilers can not handle @code{defvar}s appearing inside of 3057byte compilers can not handle @code{defvar}s appearing inside of
3057functions, while @code{(declare (special @var{var}))} takes care 3058functions, while @code{(cl-declare (special @var{var}))} takes care
3058to work correctly with all compilers. 3059to work correctly with all compilers.
3059 3060
3060@item inline 3061@item inline
@@ -3072,8 +3073,8 @@ The following declarations are all equivalent. Note that the
3072and declare it inline all at once. 3073and declare it inline all at once.
3073 3074
3074@example 3075@example
3075(declaim (inline foo bar)) 3076(cl-declaim (inline foo bar))
3076(eval-when (compile load eval) (proclaim '(inline foo bar))) 3077(cl-eval-when (compile load eval) (cl-proclaim '(inline foo bar)))
3077(defsubst foo (...) ...) ; instead of defun 3078(defsubst foo (...) ...) ; instead of defun
3078@end example 3079@end example
3079 3080
@@ -3083,10 +3084,10 @@ request that a function you have defined should be inlined,
3083but it is impolite to use it to request inlining of an external 3084but it is impolite to use it to request inlining of an external
3084function. 3085function.
3085 3086
3086In Common Lisp, it is possible to use @code{(declare (inline @dots{}))} 3087In Common Lisp, it is possible to use @code{(cl-declare (inline @dots{}))}
3087before a particular call to a function to cause just that call to 3088before a particular call to a function to cause just that call to
3088be inlined; the current byte compilers provide no way to implement 3089be inlined; the current byte compilers provide no way to implement
3089this, so @code{(declare (inline @dots{}))} is currently ignored by 3090this, so @code{(cl-declare (inline @dots{}))} is currently ignored by
3090this package. 3091this package.
3091 3092
3092@item notinline 3093@item notinline
@@ -3107,6 +3108,7 @@ and @code{safety}. The value of a quality should be an integer from
3107The default level for both qualities is 1. 3108The default level for both qualities is 1.
3108 3109
3109In this package, with the optimizing compiler, the 3110In this package, with the optimizing compiler, the
3111@c FIXME does not exist?
3110@code{speed} quality is tied to the @code{byte-compile-optimize} 3112@code{speed} quality is tied to the @code{byte-compile-optimize}
3111flag, which is set to @code{nil} for @code{(speed 0)} and to 3113flag, which is set to @code{nil} for @code{(speed 0)} and to
3112@code{t} for higher settings; and the @code{safety} quality is 3114@code{t} for higher settings; and the @code{safety} quality is
@@ -3125,10 +3127,10 @@ Emacs itself, Emacs will not crash with a segmentation fault
3125just because of an error in a fully-optimized Lisp program. 3127just because of an error in a fully-optimized Lisp program.
3126 3128
3127The @code{optimize} declaration is normally used in a top-level 3129The @code{optimize} declaration is normally used in a top-level
3128@code{proclaim} or @code{declaim} in a file; Common Lisp allows 3130@code{cl-proclaim} or @code{cl-declaim} in a file; Common Lisp allows
3129it to be used with @code{declare} to set the level of optimization 3131it to be used with @code{cl-declare} to set the level of optimization
3130locally for a given form, but this will not work correctly with the 3132locally for a given form, but this will not work correctly with the
3131current version of the optimizing compiler. (The @code{declare} 3133current version of the optimizing compiler. (The @code{cl-declare}
3132will set the new optimization level, but that level will not 3134will set the new optimization level, but that level will not
3133automatically be unset after the enclosing form is done.) 3135automatically be unset after the enclosing form is done.)
3134 3136
@@ -3152,8 +3154,8 @@ This package defines several symbol-related features that were
3152missing from Emacs Lisp. 3154missing from Emacs Lisp.
3153 3155
3154@menu 3156@menu
3155* Property Lists:: @code{get*}, @code{remprop}, @code{getf}, @code{remf}. 3157* Property Lists:: @code{cl-get}, @code{cl-remprop}, @code{cl-getf}, @code{cl-remf}.
3156* Creating Symbols:: @code{gensym}, @code{gentemp}. 3158* Creating Symbols:: @code{cl-gensym}, @code{cl-gentemp}.
3157@end menu 3159@end menu
3158 3160
3159@node Property Lists 3161@node Property Lists
@@ -3165,18 +3167,18 @@ and @code{put} for operating on properties attached to symbols.
3165There are also functions for working with property lists as 3167There are also functions for working with property lists as
3166first-class data structures not attached to particular symbols. 3168first-class data structures not attached to particular symbols.
3167 3169
3168@defun get* symbol property &optional default 3170@defun cl-get symbol property &optional default
3169This function is like @code{get}, except that if the property is 3171This function is like @code{get}, except that if the property is
3170not found, the @var{default} argument provides the return value. 3172not found, the @var{default} argument provides the return value.
3171(The Emacs Lisp @code{get} function always uses @code{nil} as 3173(The Emacs Lisp @code{get} function always uses @code{nil} as
3172the default; this package's @code{get*} is equivalent to Common 3174the default; this package's @code{cl-get} is equivalent to Common
3173Lisp's @code{get}.) 3175Lisp's @code{get}.)
3174 3176
3175The @code{get*} function is @code{setf}-able; when used in this 3177The @code{cl-get} function is @code{setf}-able; when used in this
3176fashion, the @var{default} argument is allowed but ignored. 3178fashion, the @var{default} argument is allowed but ignored.
3177@end defun 3179@end defun
3178 3180
3179@defun remprop symbol property 3181@defun cl-remprop symbol property
3180This function removes the entry for @var{property} from the property 3182This function removes the entry for @var{property} from the property
3181list of @var{symbol}. It returns a true value if the property was 3183list of @var{symbol}. It returns a true value if the property was
3182indeed found and removed, or @code{nil} if there was no such property. 3184indeed found and removed, or @code{nil} if there was no such property.
@@ -3184,10 +3186,10 @@ indeed found and removed, or @code{nil} if there was no such property.
3184since @code{get} did not allow a @var{default}, it was very difficult 3186since @code{get} did not allow a @var{default}, it was very difficult
3185to distinguish between a missing property and a property whose value 3187to distinguish between a missing property and a property whose value
3186was @code{nil}; thus, setting a property to @code{nil} was close 3188was @code{nil}; thus, setting a property to @code{nil} was close
3187enough to @code{remprop} for most purposes.) 3189enough to @code{cl-remprop} for most purposes.)
3188@end defun 3190@end defun
3189 3191
3190@defun getf place property &optional default 3192@defun cl-getf place property &optional default
3191This function scans the list @var{place} as if it were a property 3193This function scans the list @var{place} as if it were a property
3192list, i.e., a list of alternating property names and values. If 3194list, i.e., a list of alternating property names and values. If
3193an even-numbered element of @var{place} is found which is @code{eq} 3195an even-numbered element of @var{place} is found which is @code{eq}
@@ -3198,7 +3200,7 @@ is given).
3198In particular, 3200In particular,
3199 3201
3200@example 3202@example
3201(get sym prop) @equiv{} (getf (symbol-plist sym) prop) 3203(get sym prop) @equiv{} (cl-get (symbol-plist sym) prop)
3202@end example 3204@end example
3203 3205
3204It is valid to use @code{getf} as a @code{setf} place, in which case 3206It is valid to use @code{getf} as a @code{setf} place, in which case
@@ -3209,25 +3211,26 @@ list that corresponds to @var{property}, or to cons a new property-value
3209pair onto the list if the property is not yet present. 3211pair onto the list if the property is not yet present.
3210 3212
3211@example 3213@example
3212(put sym prop val) @equiv{} (setf (getf (symbol-plist sym) prop) val) 3214(put sym prop val) @equiv{} (setf (cl-get (symbol-plist sym) prop) val)
3213@end example 3215@end example
3214 3216
3215The @code{get} and @code{get*} functions are also @code{setf}-able. 3217The @code{get} and @code{cl-get} functions are also @code{setf}-able.
3216The fact that @code{default} is ignored can sometimes be useful: 3218The fact that @code{default} is ignored can sometimes be useful:
3217 3219
3218@example 3220@example
3219(incf (get* 'foo 'usage-count 0)) 3221(cl-incf (cl-get 'foo 'usage-count 0))
3220@end example 3222@end example
3221 3223
3222Here, symbol @code{foo}'s @code{usage-count} property is incremented 3224Here, symbol @code{foo}'s @code{usage-count} property is incremented
3223if it exists, or set to 1 (an incremented 0) otherwise. 3225if it exists, or set to 1 (an incremented 0) otherwise.
3224 3226
3227@c FIXME cl-getf?
3225When not used as a @code{setf} form, @code{getf} is just a regular 3228When not used as a @code{setf} form, @code{getf} is just a regular
3226function and its @var{place} argument can actually be any Lisp 3229function and its @var{place} argument can actually be any Lisp
3227expression. 3230expression.
3228@end defun 3231@end defun
3229 3232
3230@defspec remf place property 3233@defspec cl-remf place property
3231This macro removes the property-value pair for @var{property} from 3234This macro removes the property-value pair for @var{property} from
3232the property list stored at @var{place}, which is any @code{setf}-able 3235the property list stored at @var{place}, which is any @code{setf}-able
3233place expression. It returns true if the property was found. Note 3236place expression. It returns true if the property was found. Note
@@ -3248,7 +3251,7 @@ out the property and value cells.
3248These functions create unique symbols, typically for use as 3251These functions create unique symbols, typically for use as
3249temporary variables. 3252temporary variables.
3250 3253
3251@defun gensym &optional x 3254@defun cl-gensym &optional x
3252This function creates a new, uninterned symbol (using @code{make-symbol}) 3255This function creates a new, uninterned symbol (using @code{make-symbol})
3253with a unique name. (The name of an uninterned symbol is relevant 3256with a unique name. (The name of an uninterned symbol is relevant
3254only if the symbol is printed.) By default, the name is generated 3257only if the symbol is printed.) By default, the name is generated
@@ -3260,20 +3263,20 @@ their names will not conflict with ``real'' variables in the user's
3260code. 3263code.
3261@end defun 3264@end defun
3262 3265
3263@defvar *gensym-counter* 3266@defvar cl--gensym-counter
3264This variable holds the counter used to generate @code{gensym} names. 3267This variable holds the counter used to generate @code{cl-gensym} names.
3265It is incremented after each use by @code{gensym}. In Common Lisp 3268It is incremented after each use by @code{cl-gensym}. In Common Lisp
3266this is initialized with 0, but this package initializes it with a 3269this is initialized with 0, but this package initializes it with a
3267random (time-dependent) value to avoid trouble when two files that 3270random (time-dependent) value to avoid trouble when two files that
3268each used @code{gensym} in their compilation are loaded together. 3271each used @code{cl-gensym} in their compilation are loaded together.
3269(Uninterned symbols become interned when the compiler writes them 3272(Uninterned symbols become interned when the compiler writes them
3270out to a file and the Emacs loader loads them, so their names have to 3273out to a file and the Emacs loader loads them, so their names have to
3271be treated a bit more carefully than in Common Lisp where uninterned 3274be treated a bit more carefully than in Common Lisp where uninterned
3272symbols remain uninterned after loading.) 3275symbols remain uninterned after loading.)
3273@end defvar 3276@end defvar
3274 3277
3275@defun gentemp &optional x 3278@defun cl-gentemp &optional x
3276This function is like @code{gensym}, except that it produces a new 3279This function is like @code{cl-gensym}, except that it produces a new
3277@emph{interned} symbol. If the symbol that is generated already 3280@emph{interned} symbol. If the symbol that is generated already
3278exists, the function keeps incrementing the counter and trying 3281exists, the function keeps incrementing the counter and trying
3279again until a new symbol is generated. 3282again until a new symbol is generated.
@@ -3294,10 +3297,10 @@ This section defines a few simple Common Lisp operations on numbers
3294which were left out of Emacs Lisp. 3297which were left out of Emacs Lisp.
3295 3298
3296@menu 3299@menu
3297* Predicates on Numbers:: @code{plusp}, @code{oddp}, @code{floatp-safe}, etc. 3300* Predicates on Numbers:: @code{cl-plusp}, @code{cl-oddp}, @code{cl-floatp-safe}, etc.
3298* Numerical Functions:: @code{abs}, @code{floor*}, etc. 3301* Numerical Functions:: @code{abs}, @code{cl-floor}, etc.
3299* Random Numbers:: @code{random*}, @code{make-random-state}. 3302* Random Numbers:: @code{cl-random}, @code{cl-make-random-state}.
3300* Implementation Parameters:: @code{most-positive-float}. 3303* Implementation Parameters:: @code{cl-most-positive-float}.
3301@end menu 3304@end menu
3302 3305
3303@iftex 3306@iftex
@@ -3311,27 +3314,27 @@ which were left out of Emacs Lisp.
3311These functions return @code{t} if the specified condition is 3314These functions return @code{t} if the specified condition is
3312true of the numerical argument, or @code{nil} otherwise. 3315true of the numerical argument, or @code{nil} otherwise.
3313 3316
3314@defun plusp number 3317@defun cl-plusp number
3315This predicate tests whether @var{number} is positive. It is an 3318This predicate tests whether @var{number} is positive. It is an
3316error if the argument is not a number. 3319error if the argument is not a number.
3317@end defun 3320@end defun
3318 3321
3319@defun minusp number 3322@defun cl-minusp number
3320This predicate tests whether @var{number} is negative. It is an 3323This predicate tests whether @var{number} is negative. It is an
3321error if the argument is not a number. 3324error if the argument is not a number.
3322@end defun 3325@end defun
3323 3326
3324@defun oddp integer 3327@defun cl-oddp integer
3325This predicate tests whether @var{integer} is odd. It is an 3328This predicate tests whether @var{integer} is odd. It is an
3326error if the argument is not an integer. 3329error if the argument is not an integer.
3327@end defun 3330@end defun
3328 3331
3329@defun evenp integer 3332@defun cl-evenp integer
3330This predicate tests whether @var{integer} is even. It is an 3333This predicate tests whether @var{integer} is even. It is an
3331error if the argument is not an integer. 3334error if the argument is not an integer.
3332@end defun 3335@end defun
3333 3336
3334@defun floatp-safe object 3337@defun cl-floatp-safe object
3335This predicate tests whether @var{object} is a floating-point 3338This predicate tests whether @var{object} is a floating-point
3336number. On systems that support floating-point, this is equivalent 3339number. On systems that support floating-point, this is equivalent
3337to @code{floatp}. On other systems, this always returns @code{nil}. 3340to @code{floatp}. On other systems, this always returns @code{nil}.
@@ -3347,30 +3350,26 @@ to @code{floatp}. On other systems, this always returns @code{nil}.
3347@noindent 3350@noindent
3348These functions perform various arithmetic operations on numbers. 3351These functions perform various arithmetic operations on numbers.
3349 3352
3350@defun gcd &rest integers 3353@defun cl-gcd &rest integers
3351This function returns the Greatest Common Divisor of the arguments. 3354This function returns the Greatest Common Divisor of the arguments.
3352For one argument, it returns the absolute value of that argument. 3355For one argument, it returns the absolute value of that argument.
3353For zero arguments, it returns zero. 3356For zero arguments, it returns zero.
3354@end defun 3357@end defun
3355 3358
3356@defun lcm &rest integers 3359@defun cl-lcm &rest integers
3357This function returns the Least Common Multiple of the arguments. 3360This function returns the Least Common Multiple of the arguments.
3358For one argument, it returns the absolute value of that argument. 3361For one argument, it returns the absolute value of that argument.
3359For zero arguments, it returns one. 3362For zero arguments, it returns one.
3360@end defun 3363@end defun
3361 3364
3362@defun isqrt integer 3365@defun cl-isqrt integer
3363This function computes the ``integer square root'' of its integer 3366This function computes the ``integer square root'' of its integer
3364argument, i.e., the greatest integer less than or equal to the true 3367argument, i.e., the greatest integer less than or equal to the true
3365square root of the argument. 3368square root of the argument.
3366@end defun 3369@end defun
3367 3370
3368@defun floor* number &optional divisor 3371@defun cl-floor number &optional divisor
3369This function implements the Common Lisp @code{floor} function. 3372With one argument, @code{cl-floor} returns a list of two numbers:
3370It is called @code{floor*} to avoid name conflicts with the
3371simpler @code{floor} function built-in to Emacs.
3372
3373With one argument, @code{floor*} returns a list of two numbers:
3374The argument rounded down (toward minus infinity) to an integer, 3373The argument rounded down (toward minus infinity) to an integer,
3375and the ``remainder'' which would have to be added back to the 3374and the ``remainder'' which would have to be added back to the
3376first return value to yield the argument again. If the argument 3375first return value to yield the argument again. If the argument
@@ -3379,37 +3378,37 @@ If the argument is a floating-point number, the first
3379result is a Lisp integer and the second is a Lisp float between 3378result is a Lisp integer and the second is a Lisp float between
33800 (inclusive) and 1 (exclusive). 33790 (inclusive) and 1 (exclusive).
3381 3380
3382With two arguments, @code{floor*} divides @var{number} by 3381With two arguments, @code{cl-floor} divides @var{number} by
3383@var{divisor}, and returns the floor of the quotient and the 3382@var{divisor}, and returns the floor of the quotient and the
3384corresponding remainder as a list of two numbers. If 3383corresponding remainder as a list of two numbers. If
3385@code{(floor* @var{x} @var{y})} returns @code{(@var{q} @var{r})}, 3384@code{(cl-floor @var{x} @var{y})} returns @code{(@var{q} @var{r})},
3386then @code{@var{q}*@var{y} + @var{r} = @var{x}}, with @var{r} 3385then @code{@var{q}*@var{y} + @var{r} = @var{x}}, with @var{r}
3387between 0 (inclusive) and @var{r} (exclusive). Also, note 3386between 0 (inclusive) and @var{r} (exclusive). Also, note
3388that @code{(floor* @var{x})} is exactly equivalent to 3387that @code{(cl-floor @var{x})} is exactly equivalent to
3389@code{(floor* @var{x} 1)}. 3388@code{(cl-floor @var{x} 1)}.
3390 3389
3391This function is entirely compatible with Common Lisp's @code{floor} 3390This function is entirely compatible with Common Lisp's @code{floor}
3392function, except that it returns the two results in a list since 3391function, except that it returns the two results in a list since
3393Emacs Lisp does not support multiple-valued functions. 3392Emacs Lisp does not support multiple-valued functions.
3394@end defun 3393@end defun
3395 3394
3396@defun ceiling* number &optional divisor 3395@defun cl-ceiling number &optional divisor
3397This function implements the Common Lisp @code{ceiling} function, 3396This function implements the Common Lisp @code{ceiling} function,
3398which is analogous to @code{floor} except that it rounds the 3397which is analogous to @code{floor} except that it rounds the
3399argument or quotient of the arguments up toward plus infinity. 3398argument or quotient of the arguments up toward plus infinity.
3400The remainder will be between 0 and minus @var{r}. 3399The remainder will be between 0 and minus @var{r}.
3401@end defun 3400@end defun
3402 3401
3403@defun truncate* number &optional divisor 3402@defun cl-truncate number &optional divisor
3404This function implements the Common Lisp @code{truncate} function, 3403This function implements the Common Lisp @code{truncate} function,
3405which is analogous to @code{floor} except that it rounds the 3404which is analogous to @code{floor} except that it rounds the
3406argument or quotient of the arguments toward zero. Thus it is 3405argument or quotient of the arguments toward zero. Thus it is
3407equivalent to @code{floor*} if the argument or quotient is 3406equivalent to @code{cl-floor} if the argument or quotient is
3408positive, or to @code{ceiling*} otherwise. The remainder has 3407positive, or to @code{cl-ceiling} otherwise. The remainder has
3409the same sign as @var{number}. 3408the same sign as @var{number}.
3410@end defun 3409@end defun
3411 3410
3412@defun round* number &optional divisor 3411@defun cl-round number &optional divisor
3413This function implements the Common Lisp @code{round} function, 3412This function implements the Common Lisp @code{round} function,
3414which is analogous to @code{floor} except that it rounds the 3413which is analogous to @code{floor} except that it rounds the
3415argument or quotient of the arguments to the nearest integer. 3414argument or quotient of the arguments to the nearest integer.
@@ -3417,21 +3416,22 @@ In the case of a tie (the argument or quotient is exactly
3417halfway between two integers), it rounds to the even integer. 3416halfway between two integers), it rounds to the even integer.
3418@end defun 3417@end defun
3419 3418
3420@defun mod* number divisor 3419@defun cl-mod number divisor
3421This function returns the same value as the second return value 3420This function returns the same value as the second return value
3422of @code{floor}. 3421of @code{cl-floor}.
3423@end defun 3422@end defun
3424 3423
3425@defun rem* number divisor 3424@defun cl-rem number divisor
3426This function returns the same value as the second return value 3425This function returns the same value as the second return value
3427of @code{truncate}. 3426of @code{cl-truncate}.
3428@end defun 3427@end defun
3429 3428
3429@c FIXME this stuff is probably no longer of interest to anyone.
3430These definitions are compatible with those in the Quiroz 3430These definitions are compatible with those in the Quiroz
3431@file{cl.el} package, except that this package appends @samp{*} 3431@file{cl.el} package, except that
3432to certain function names to avoid conflicts with existing 3432@c this package appends @samp{*} to certain function names to avoid
3433Emacs functions, and that the mechanism for returning 3433@c conflicts with existing Emacs functions, and that
3434multiple values is different. 3434the mechanism for returning multiple values is different.
3435 3435
3436@iftex 3436@iftex
3437@secno=8 3437@secno=8
@@ -3447,7 +3447,7 @@ algorithm, which is much more likely to give statistically clean
3447random numbers than the simple generators supplied by many 3447random numbers than the simple generators supplied by many
3448operating systems. 3448operating systems.
3449 3449
3450@defun random* number &optional state 3450@defun cl-random number &optional state
3451This function returns a random nonnegative number less than 3451This function returns a random nonnegative number less than
3452@var{number}, and of the same type (either integer or floating-point). 3452@var{number}, and of the same type (either integer or floating-point).
3453The @var{state} argument should be a @code{random-state} object 3453The @var{state} argument should be a @code{random-state} object
@@ -3458,21 +3458,21 @@ function modifies this state object as a side effect. If
3458@code{random-state} object. 3458@code{random-state} object.
3459@end defun 3459@end defun
3460 3460
3461@defvar *random-state* 3461@defvar cl--random-state
3462This variable contains the system ``default'' @code{random-state} 3462This variable contains the system ``default'' @code{random-state}
3463object, used for calls to @code{random*} that do not specify an 3463object, used for calls to @code{cl-random} that do not specify an
3464alternative state object. Since any number of programs in the 3464alternative state object. Since any number of programs in the
3465Emacs process may be accessing @code{*random-state*} in interleaved 3465Emacs process may be accessing @code{cl--random-state} in interleaved
3466fashion, the sequence generated from this variable will be 3466fashion, the sequence generated from this variable will be
3467irreproducible for all intents and purposes. 3467irreproducible for all intents and purposes.
3468@end defvar 3468@end defvar
3469 3469
3470@defun make-random-state &optional state 3470@defun cl-make-random-state &optional state
3471This function creates or copies a @code{random-state} object. 3471This function creates or copies a @code{random-state} object.
3472If @var{state} is omitted or @code{nil}, it returns a new copy of 3472If @var{state} is omitted or @code{nil}, it returns a new copy of
3473@code{*random-state*}. This is a copy in the sense that future 3473@code{cl--random-state}. This is a copy in the sense that future
3474sequences of calls to @code{(random* @var{n})} and 3474sequences of calls to @code{(cl-random @var{n})} and
3475@code{(random* @var{n} @var{s})} (where @var{s} is the new 3475@code{(cl-random @var{n} @var{s})} (where @var{s} is the new
3476random-state object) will return identical sequences of random 3476random-state object) will return identical sequences of random
3477numbers. 3477numbers.
3478 3478
@@ -3487,13 +3487,13 @@ different sequence of random numbers.
3487It is valid to print a @code{random-state} object to a buffer or 3487It is valid to print a @code{random-state} object to a buffer or
3488file and later read it back with @code{read}. If a program wishes 3488file and later read it back with @code{read}. If a program wishes
3489to use a sequence of pseudo-random numbers which can be reproduced 3489to use a sequence of pseudo-random numbers which can be reproduced
3490later for debugging, it can call @code{(make-random-state t)} to 3490later for debugging, it can call @code{(cl-make-random-state t)} to
3491get a new sequence, then print this sequence to a file. When the 3491get a new sequence, then print this sequence to a file. When the
3492program is later rerun, it can read the original run's random-state 3492program is later rerun, it can read the original run's random-state
3493from the file. 3493from the file.
3494@end defun 3494@end defun
3495 3495
3496@defun random-state-p object 3496@defun cl-random-state-p object
3497This predicate returns @code{t} if @var{object} is a 3497This predicate returns @code{t} if @var{object} is a
3498@code{random-state} object, or @code{nil} otherwise. 3498@code{random-state} object, or @code{nil} otherwise.
3499@end defun 3499@end defun
@@ -3512,7 +3512,7 @@ function that must be called before the parameters can be used.
3512 3512
3513@defun cl-float-limits 3513@defun cl-float-limits
3514This function makes sure that the Common Lisp floating-point parameters 3514This function makes sure that the Common Lisp floating-point parameters
3515like @code{most-positive-float} have been initialized. Until it is 3515like @code{cl-most-positive-float} have been initialized. Until it is
3516called, these parameters will be @code{nil}. If this version of Emacs 3516called, these parameters will be @code{nil}. If this version of Emacs
3517does not support floats, the parameters will remain @code{nil}. If the 3517does not support floats, the parameters will remain @code{nil}. If the
3518parameters have already been initialized, the function returns 3518parameters have already been initialized, the function returns
@@ -3530,50 +3530,50 @@ precisions, it has families of constants like
3530floating-point precision, so this package omits the precision word 3530floating-point precision, so this package omits the precision word
3531from the constants' names. 3531from the constants' names.
3532 3532
3533@defvar most-positive-float 3533@defvar cl-most-positive-float
3534This constant equals the largest value a Lisp float can hold. 3534This constant equals the largest value a Lisp float can hold.
3535For those systems whose arithmetic supports infinities, this is 3535For those systems whose arithmetic supports infinities, this is
3536the largest @emph{finite} value. For IEEE machines, the value 3536the largest @emph{finite} value. For IEEE machines, the value
3537is approximately @code{1.79e+308}. 3537is approximately @code{1.79e+308}.
3538@end defvar 3538@end defvar
3539 3539
3540@defvar most-negative-float 3540@defvar cl-most-negative-float
3541This constant equals the most-negative value a Lisp float can hold. 3541This constant equals the most-negative value a Lisp float can hold.
3542(It is assumed to be equal to @code{(- most-positive-float)}.) 3542(It is assumed to be equal to @code{(- cl-most-positive-float)}.)
3543@end defvar 3543@end defvar
3544 3544
3545@defvar least-positive-float 3545@defvar cl-least-positive-float
3546This constant equals the smallest Lisp float value greater than zero. 3546This constant equals the smallest Lisp float value greater than zero.
3547For IEEE machines, it is about @code{4.94e-324} if denormals are 3547For IEEE machines, it is about @code{4.94e-324} if denormals are
3548supported or @code{2.22e-308} if not. 3548supported or @code{2.22e-308} if not.
3549@end defvar 3549@end defvar
3550 3550
3551@defvar least-positive-normalized-float 3551@defvar cl-least-positive-normalized-float
3552This constant equals the smallest @emph{normalized} Lisp float greater 3552This constant equals the smallest @emph{normalized} Lisp float greater
3553than zero, i.e., the smallest value for which IEEE denormalization 3553than zero, i.e., the smallest value for which IEEE denormalization
3554will not result in a loss of precision. For IEEE machines, this 3554will not result in a loss of precision. For IEEE machines, this
3555value is about @code{2.22e-308}. For machines that do not support 3555value is about @code{2.22e-308}. For machines that do not support
3556the concept of denormalization and gradual underflow, this constant 3556the concept of denormalization and gradual underflow, this constant
3557will always equal @code{least-positive-float}. 3557will always equal @code{cl-least-positive-float}.
3558@end defvar 3558@end defvar
3559 3559
3560@defvar least-negative-float 3560@defvar cl-least-negative-float
3561This constant is the negative counterpart of @code{least-positive-float}. 3561This constant is the negative counterpart of @code{cl-least-positive-float}.
3562@end defvar 3562@end defvar
3563 3563
3564@defvar least-negative-normalized-float 3564@defvar cl-least-negative-normalized-float
3565This constant is the negative counterpart of 3565This constant is the negative counterpart of
3566@code{least-positive-normalized-float}. 3566@code{cl-least-positive-normalized-float}.
3567@end defvar 3567@end defvar
3568 3568
3569@defvar float-epsilon 3569@defvar cl-float-epsilon
3570This constant is the smallest positive Lisp float that can be added 3570This constant is the smallest positive Lisp float that can be added
3571to 1.0 to produce a distinct value. Adding a smaller number to 1.0 3571to 1.0 to produce a distinct value. Adding a smaller number to 1.0
3572will yield 1.0 again due to roundoff. For IEEE machines, epsilon 3572will yield 1.0 again due to roundoff. For IEEE machines, epsilon
3573is about @code{2.22e-16}. 3573is about @code{2.22e-16}.
3574@end defvar 3574@end defvar
3575 3575
3576@defvar float-negative-epsilon 3576@defvar cl-float-negative-epsilon
3577This is the smallest positive value that can be subtracted from 3577This is the smallest positive value that can be subtracted from
35781.0 to produce a distinct value. For IEEE machines, it is about 35781.0 to produce a distinct value. For IEEE machines, it is about
3579@code{1.11e-16}. 3579@code{1.11e-16}.
@@ -3590,10 +3590,10 @@ Emacs Lisp includes a few of these, notably @code{elt} and
3590 3590
3591@menu 3591@menu
3592* Sequence Basics:: Arguments shared by all sequence functions. 3592* Sequence Basics:: Arguments shared by all sequence functions.
3593* Mapping over Sequences:: @code{mapcar*}, @code{mapcan}, @code{map}, @code{every}, etc. 3593* Mapping over Sequences:: @code{cl-mapcar}, @code{cl-mapcan}, @code{cl-map}, @code{cl-every}, etc.
3594* Sequence Functions:: @code{subseq}, @code{remove*}, @code{substitute}, etc. 3594* Sequence Functions:: @code{cl-subseq}, @code{cl-remove}, @code{cl-substitute}, etc.
3595* Searching Sequences:: @code{find}, @code{position}, @code{count}, @code{search}, etc. 3595* Searching Sequences:: @code{cl-find}, @code{cl-position}, @code{cl-count}, @code{cl-search}, etc.
3596* Sorting Sequences:: @code{sort*}, @code{stable-sort}, @code{merge}. 3596* Sorting Sequences:: @code{cl-sort}, @code{cl-stable-sort}, @code{cl-merge}.
3597@end menu 3597@end menu
3598 3598
3599@node Sequence Basics 3599@node Sequence Basics
@@ -3607,7 +3607,7 @@ may appear in any order.
3607The @code{:key} argument should be passed either @code{nil}, or a 3607The @code{:key} argument should be passed either @code{nil}, or a
3608function of one argument. This key function is used as a filter 3608function of one argument. This key function is used as a filter
3609through which the elements of the sequence are seen; for example, 3609through which the elements of the sequence are seen; for example,
3610@code{(find x y :key 'car)} is similar to @code{(assoc* x y)}: 3610@code{(cl-find x y :key 'car)} is similar to @code{(cl-assoc x y)}:
3611It searches for an element of the list whose @code{car} equals 3611It searches for an element of the list whose @code{car} equals
3612@code{x}, rather than for an element which equals @code{x} itself. 3612@code{x}, rather than for an element which equals @code{x} itself.
3613If @code{:key} is omitted or @code{nil}, the filter is effectively 3613If @code{:key} is omitted or @code{nil}, the filter is effectively
@@ -3632,7 +3632,7 @@ and sequence elements match if the predicate returns true on them
3632(or false in the case of @code{-if-not}). For example: 3632(or false in the case of @code{-if-not}). For example:
3633 3633
3634@example 3634@example
3635(remove* 0 seq :test '=) @equiv{} (remove-if 'zerop seq) 3635(cl-remove 0 seq :test '=) @equiv{} (cl-remove-if 'zerop seq)
3636@end example 3636@end example
3637 3637
3638@noindent 3638@noindent
@@ -3662,14 +3662,14 @@ are called on various elements. Therefore, it is a bad idea to depend
3662on side effects of these functions. For example, @code{:from-end} 3662on side effects of these functions. For example, @code{:from-end}
3663may cause the sequence to be scanned actually in reverse, or it may 3663may cause the sequence to be scanned actually in reverse, or it may
3664be scanned forwards but computing a result ``as if'' it were scanned 3664be scanned forwards but computing a result ``as if'' it were scanned
3665backwards. (Some functions, like @code{mapcar*} and @code{every}, 3665backwards. (Some functions, like @code{cl-mapcar} and @code{cl-every},
3666@emph{do} specify exactly the order in which the function is called 3666@emph{do} specify exactly the order in which the function is called
3667so side effects are perfectly acceptable in those cases.) 3667so side effects are perfectly acceptable in those cases.)
3668 3668
3669Strings may contain ``text properties'' as well 3669Strings may contain ``text properties'' as well
3670as character data. Except as noted, it is undefined whether or 3670as character data. Except as noted, it is undefined whether or
3671not text properties are preserved by sequence functions. For 3671not text properties are preserved by sequence functions. For
3672example, @code{(remove* ?A @var{str})} may or may not preserve 3672example, @code{(cl-remove ?A @var{str})} may or may not preserve
3673the properties of the characters copied from @var{str} into the 3673the properties of the characters copied from @var{str} into the
3674result. 3674result.
3675 3675
@@ -3681,7 +3681,7 @@ These functions ``map'' the function you specify over the elements
3681of lists or arrays. They are all variations on the theme of the 3681of lists or arrays. They are all variations on the theme of the
3682built-in function @code{mapcar}. 3682built-in function @code{mapcar}.
3683 3683
3684@defun mapcar* function seq &rest more-seqs 3684@defun cl-mapcar function seq &rest more-seqs
3685This function calls @var{function} on successive parallel sets of 3685This function calls @var{function} on successive parallel sets of
3686elements from its argument sequences. Given a single @var{seq} 3686elements from its argument sequences. Given a single @var{seq}
3687argument it is equivalent to @code{mapcar}; given @var{n} sequences, 3687argument it is equivalent to @code{mapcar}; given @var{n} sequences,
@@ -3694,86 +3694,87 @@ is always a list.
3694 3694
3695Common Lisp's @code{mapcar} accepts multiple arguments but works 3695Common Lisp's @code{mapcar} accepts multiple arguments but works
3696only on lists; Emacs Lisp's @code{mapcar} accepts a single sequence 3696only on lists; Emacs Lisp's @code{mapcar} accepts a single sequence
3697argument. This package's @code{mapcar*} works as a compatible 3697argument. This package's @code{cl-mapcar} works as a compatible
3698superset of both. 3698superset of both.
3699@end defun 3699@end defun
3700 3700
3701@defun map result-type function seq &rest more-seqs 3701@defun cl-map result-type function seq &rest more-seqs
3702This function maps @var{function} over the argument sequences, 3702This function maps @var{function} over the argument sequences,
3703just like @code{mapcar*}, but it returns a sequence of type 3703just like @code{cl-mapcar}, but it returns a sequence of type
3704@var{result-type} rather than a list. @var{result-type} must 3704@var{result-type} rather than a list. @var{result-type} must
3705be one of the following symbols: @code{vector}, @code{string}, 3705be one of the following symbols: @code{vector}, @code{string},
3706@code{list} (in which case the effect is the same as for 3706@code{list} (in which case the effect is the same as for
3707@code{mapcar*}), or @code{nil} (in which case the results are 3707@code{mapcar*}), or @code{nil} (in which case the results are
3708thrown away and @code{map} returns @code{nil}). 3708thrown away and @code{cl-map} returns @code{nil}).
3709@end defun 3709@end defun
3710 3710
3711@defun maplist function list &rest more-lists 3711@defun cl-maplist function list &rest more-lists
3712This function calls @var{function} on each of its argument lists, 3712This function calls @var{function} on each of its argument lists,
3713then on the @code{cdr}s of those lists, and so on, until the 3713then on the @code{cdr}s of those lists, and so on, until the
3714shortest list runs out. The results are returned in the form 3714shortest list runs out. The results are returned in the form
3715of a list. Thus, @code{maplist} is like @code{mapcar*} except 3715of a list. Thus, @code{cl-maplist} is like @code{cl-mapcar} except
3716that it passes in the list pointers themselves rather than the 3716that it passes in the list pointers themselves rather than the
3717@code{car}s of the advancing pointers. 3717@code{car}s of the advancing pointers.
3718@end defun 3718@end defun
3719 3719
3720@c FIXME does not exist?
3720@defun cl-mapc function seq &rest more-seqs 3721@defun cl-mapc function seq &rest more-seqs
3721This function is like @code{mapcar*}, except that the values returned 3722This function is like @code{cl-mapcar}, except that the values returned
3722by @var{function} are ignored and thrown away rather than being 3723by @var{function} are ignored and thrown away rather than being
3723collected into a list. The return value of @code{cl-mapc} is @var{seq}, 3724collected into a list. The return value of @code{cl-mapc} is @var{seq},
3724the first sequence. This function is more general than the Emacs 3725the first sequence. This function is more general than the Emacs
3725primitive @code{mapc}. 3726primitive @code{mapc}.
3726@end defun 3727@end defun
3727 3728
3728@defun mapl function list &rest more-lists 3729@defun cl-mapl function list &rest more-lists
3729This function is like @code{maplist}, except that it throws away 3730This function is like @code{cl-maplist}, except that it throws away
3730the values returned by @var{function}. 3731the values returned by @var{function}.
3731@end defun 3732@end defun
3732 3733
3733@defun mapcan function seq &rest more-seqs 3734@defun cl-mapcan function seq &rest more-seqs
3734This function is like @code{mapcar*}, except that it concatenates 3735This function is like @code{cl-mapcar}, except that it concatenates
3735the return values (which must be lists) using @code{nconc}, 3736the return values (which must be lists) using @code{nconc},
3736rather than simply collecting them into a list. 3737rather than simply collecting them into a list.
3737@end defun 3738@end defun
3738 3739
3739@defun mapcon function list &rest more-lists 3740@defun cl-mapcon function list &rest more-lists
3740This function is like @code{maplist}, except that it concatenates 3741This function is like @code{cl-maplist}, except that it concatenates
3741the return values using @code{nconc}. 3742the return values using @code{nconc}.
3742@end defun 3743@end defun
3743 3744
3744@defun some predicate seq &rest more-seqs 3745@defun cl-some predicate seq &rest more-seqs
3745This function calls @var{predicate} on each element of @var{seq} 3746This function calls @var{predicate} on each element of @var{seq}
3746in turn; if @var{predicate} returns a non-@code{nil} value, 3747in turn; if @var{predicate} returns a non-@code{nil} value,
3747@code{some} returns that value, otherwise it returns @code{nil}. 3748@code{some} returns that value, otherwise it returns @code{nil}.
3748Given several sequence arguments, it steps through the sequences 3749Given several sequence arguments, it steps through the sequences
3749in parallel until the shortest one runs out, just as in 3750in parallel until the shortest one runs out, just as in
3750@code{mapcar*}. You can rely on the left-to-right order in which 3751@code{cl-mapcar}. You can rely on the left-to-right order in which
3751the elements are visited, and on the fact that mapping stops 3752the elements are visited, and on the fact that mapping stops
3752immediately as soon as @var{predicate} returns non-@code{nil}. 3753immediately as soon as @var{predicate} returns non-@code{nil}.
3753@end defun 3754@end defun
3754 3755
3755@defun every predicate seq &rest more-seqs 3756@defun cl-every predicate seq &rest more-seqs
3756This function calls @var{predicate} on each element of the sequence(s) 3757This function calls @var{predicate} on each element of the sequence(s)
3757in turn; it returns @code{nil} as soon as @var{predicate} returns 3758in turn; it returns @code{nil} as soon as @var{predicate} returns
3758@code{nil} for any element, or @code{t} if the predicate was true 3759@code{nil} for any element, or @code{t} if the predicate was true
3759for all elements. 3760for all elements.
3760@end defun 3761@end defun
3761 3762
3762@defun notany predicate seq &rest more-seqs 3763@defun cl-notany predicate seq &rest more-seqs
3763This function calls @var{predicate} on each element of the sequence(s) 3764This function calls @var{predicate} on each element of the sequence(s)
3764in turn; it returns @code{nil} as soon as @var{predicate} returns 3765in turn; it returns @code{nil} as soon as @var{predicate} returns
3765a non-@code{nil} value for any element, or @code{t} if the predicate 3766a non-@code{nil} value for any element, or @code{t} if the predicate
3766was @code{nil} for all elements. 3767was @code{nil} for all elements.
3767@end defun 3768@end defun
3768 3769
3769@defun notevery predicate seq &rest more-seqs 3770@defun cl-notevery predicate seq &rest more-seqs
3770This function calls @var{predicate} on each element of the sequence(s) 3771This function calls @var{predicate} on each element of the sequence(s)
3771in turn; it returns a non-@code{nil} value as soon as @var{predicate} 3772in turn; it returns a non-@code{nil} value as soon as @var{predicate}
3772returns @code{nil} for any element, or @code{t} if the predicate was 3773returns @code{nil} for any element, or @code{t} if the predicate was
3773true for all elements. 3774true for all elements.
3774@end defun 3775@end defun
3775 3776
3776@defun reduce function seq @t{&key :from-end :start :end :initial-value :key} 3777@defun cl-reduce function seq @t{&key :from-end :start :end :initial-value :key}
3777This function combines the elements of @var{seq} using an associative 3778This function combines the elements of @var{seq} using an associative
3778binary operation. Suppose @var{function} is @code{*} and @var{seq} is 3779binary operation. Suppose @var{function} is @code{*} and @var{seq} is
3779the list @code{(2 3 4 5)}. The first two elements of the list are 3780the list @code{(2 3 4 5)}. The first two elements of the list are
@@ -3781,16 +3782,16 @@ combined with @code{(* 2 3) = 6}; this is combined with the next
3781element, @code{(* 6 4) = 24}, and that is combined with the final 3782element, @code{(* 6 4) = 24}, and that is combined with the final
3782element: @code{(* 24 5) = 120}. Note that the @code{*} function happens 3783element: @code{(* 24 5) = 120}. Note that the @code{*} function happens
3783to be self-reducing, so that @code{(* 2 3 4 5)} has the same effect as 3784to be self-reducing, so that @code{(* 2 3 4 5)} has the same effect as
3784an explicit call to @code{reduce}. 3785an explicit call to @code{cl-reduce}.
3785 3786
3786If @code{:from-end} is true, the reduction is right-associative instead 3787If @code{:from-end} is true, the reduction is right-associative instead
3787of left-associative: 3788of left-associative:
3788 3789
3789@example 3790@example
3790(reduce '- '(1 2 3 4)) 3791(cl-reduce '- '(1 2 3 4))
3791 @equiv{} (- (- (- 1 2) 3) 4) @result{} -8 3792 @equiv{} (- (- (- 1 2) 3) 4) @result{} -8
3792(reduce '- '(1 2 3 4) :from-end t) 3793(cl-reduce '- '(1 2 3 4) :from-end t)
3793 @equiv{} (- 1 (- 2 (- 3 4))) @result{} -2 3794 @equiv{} (- 1 (- 2 (- 3 4))) @result{} -2
3794@end example 3795@end example
3795 3796
3796If @code{:key} is specified, it is a function of one argument which 3797If @code{:key} is specified, it is a function of one argument which
@@ -3807,7 +3808,7 @@ If the sequence is empty (and there is no initial value), then
3807@end defun 3808@end defun
3808 3809
3809All of these mapping operations can be expressed conveniently in 3810All of these mapping operations can be expressed conveniently in
3810terms of the @code{loop} macro. In compiled code, @code{loop} will 3811terms of the @code{cl-loop} macro. In compiled code, @code{cl-loop} will
3811be faster since it generates the loop as in-line code with no 3812be faster since it generates the loop as in-line code with no
3812function calls. 3813function calls.
3813 3814
@@ -3818,7 +3819,7 @@ function calls.
3818This section describes a number of Common Lisp functions for 3819This section describes a number of Common Lisp functions for
3819operating on sequences. 3820operating on sequences.
3820 3821
3821@defun subseq sequence start &optional end 3822@defun cl-subseq sequence start &optional end
3822This function returns a given subsequence of the argument 3823This function returns a given subsequence of the argument
3823@var{sequence}, which may be a list, string, or vector. 3824@var{sequence}, which may be a list, string, or vector.
3824The indices @var{start} and @var{end} must be in range, and 3825The indices @var{start} and @var{end} must be in range, and
@@ -3830,30 +3831,30 @@ with @var{sequence}.
3830As an extension to Common Lisp, @var{start} and/or @var{end} 3831As an extension to Common Lisp, @var{start} and/or @var{end}
3831may be negative, in which case they represent a distance back 3832may be negative, in which case they represent a distance back
3832from the end of the sequence. This is for compatibility with 3833from the end of the sequence. This is for compatibility with
3833Emacs's @code{substring} function. Note that @code{subseq} is 3834Emacs's @code{substring} function. Note that @code{cl-subseq} is
3834the @emph{only} sequence function that allows negative 3835the @emph{only} sequence function that allows negative
3835@var{start} and @var{end}. 3836@var{start} and @var{end}.
3836 3837
3837You can use @code{setf} on a @code{subseq} form to replace a 3838You can use @code{setf} on a @code{cl-subseq} form to replace a
3838specified range of elements with elements from another sequence. 3839specified range of elements with elements from another sequence.
3839The replacement is done as if by @code{replace}, described below. 3840The replacement is done as if by @code{cl-replace}, described below.
3840@end defun 3841@end defun
3841 3842
3842@defun concatenate result-type &rest seqs 3843@defun cl-concatenate result-type &rest seqs
3843This function concatenates the argument sequences together to 3844This function concatenates the argument sequences together to
3844form a result sequence of type @var{result-type}, one of the 3845form a result sequence of type @var{result-type}, one of the
3845symbols @code{vector}, @code{string}, or @code{list}. The 3846symbols @code{vector}, @code{string}, or @code{list}. The
3846arguments are always copied, even in cases such as 3847arguments are always copied, even in cases such as
3847@code{(concatenate 'list '(1 2 3))} where the result is 3848@code{(cl-concatenate 'list '(1 2 3))} where the result is
3848identical to an argument. 3849identical to an argument.
3849@end defun 3850@end defun
3850 3851
3851@defun fill seq item @t{&key :start :end} 3852@defun cl-fill seq item @t{&key :start :end}
3852This function fills the elements of the sequence (or the specified 3853This function fills the elements of the sequence (or the specified
3853part of the sequence) with the value @var{item}. 3854part of the sequence) with the value @var{item}.
3854@end defun 3855@end defun
3855 3856
3856@defun replace seq1 seq2 @t{&key :start1 :end1 :start2 :end2} 3857@defun cl-replace seq1 seq2 @t{&key :start1 :end1 :start2 :end2}
3857This function copies part of @var{seq2} into part of @var{seq1}. 3858This function copies part of @var{seq2} into part of @var{seq1}.
3858The sequence @var{seq1} is not stretched or resized; the amount 3859The sequence @var{seq1} is not stretched or resized; the amount
3859of data copied is simply the shorter of the source and destination 3860of data copied is simply the shorter of the source and destination
@@ -3867,7 +3868,7 @@ start and end arguments specify overlapping regions, the effect
3867is undefined. 3868is undefined.
3868@end defun 3869@end defun
3869 3870
3870@defun remove* item seq @t{&key :test :test-not :key :count :start :end :from-end} 3871@defun cl-remove item seq @t{&key :test :test-not :key :count :start :end :from-end}
3871This returns a copy of @var{seq} with all elements matching 3872This returns a copy of @var{seq} with all elements matching
3872@var{item} removed. The result may share storage with or be 3873@var{item} removed. The result may share storage with or be
3873@code{eq} to @var{seq} in some circumstances, but the original 3874@code{eq} to @var{seq} in some circumstances, but the original
@@ -3884,25 +3885,25 @@ end of the sequence rather than the beginning (this matters only
3884if @var{count} was also specified). 3885if @var{count} was also specified).
3885@end defun 3886@end defun
3886 3887
3887@defun delete* item seq @t{&key :test :test-not :key :count :start :end :from-end} 3888@defun cl-delete item seq @t{&key :test :test-not :key :count :start :end :from-end}
3888This deletes all elements of @var{seq} which match @var{item}. 3889This deletes all elements of @var{seq} which match @var{item}.
3889It is a destructive operation. Since Emacs Lisp does not support 3890It is a destructive operation. Since Emacs Lisp does not support
3890stretchable strings or vectors, this is the same as @code{remove*} 3891stretchable strings or vectors, this is the same as @code{cl-remove}
3891for those sequence types. On lists, @code{remove*} will copy the 3892for those sequence types. On lists, @code{cl-remove} will copy the
3892list if necessary to preserve the original list, whereas 3893list if necessary to preserve the original list, whereas
3893@code{delete*} will splice out parts of the argument list. 3894@code{cl-delete} will splice out parts of the argument list.
3894Compare @code{append} and @code{nconc}, which are analogous 3895Compare @code{append} and @code{nconc}, which are analogous
3895non-destructive and destructive list operations in Emacs Lisp. 3896non-destructive and destructive list operations in Emacs Lisp.
3896@end defun 3897@end defun
3897 3898
3898@findex remove-if 3899@findex cl-remove-if
3899@findex remove-if-not 3900@findex cl-remove-if-not
3900@findex delete-if 3901@findex cl-delete-if
3901@findex delete-if-not 3902@findex cl-delete-if-not
3902The predicate-oriented functions @code{remove-if}, @code{remove-if-not}, 3903The predicate-oriented functions @code{cl-remove-if}, @code{cl-remove-if-not},
3903@code{delete-if}, and @code{delete-if-not} are defined similarly. 3904@code{cl-delete-if}, and @code{cl-delete-if-not} are defined similarly.
3904 3905
3905@defun remove-duplicates seq @t{&key :test :test-not :key :start :end :from-end} 3906@defun cl-remove-duplicates seq @t{&key :test :test-not :key :start :end :from-end}
3906This function returns a copy of @var{seq} with duplicate elements 3907This function returns a copy of @var{seq} with duplicate elements
3907removed. Specifically, if two elements from the sequence match 3908removed. Specifically, if two elements from the sequence match
3908according to the @code{:test}, @code{:test-not}, and @code{:key} 3909according to the @code{:test}, @code{:test-not}, and @code{:key}
@@ -3912,30 +3913,30 @@ is true, the leftmost one is retained instead. If @code{:start} or
3912examined or removed. 3913examined or removed.
3913@end defun 3914@end defun
3914 3915
3915@defun delete-duplicates seq @t{&key :test :test-not :key :start :end :from-end} 3916@defun cl-delete-duplicates seq @t{&key :test :test-not :key :start :end :from-end}
3916This function deletes duplicate elements from @var{seq}. It is 3917This function deletes duplicate elements from @var{seq}. It is
3917a destructive version of @code{remove-duplicates}. 3918a destructive version of @code{cl-remove-duplicates}.
3918@end defun 3919@end defun
3919 3920
3920@defun substitute new old seq @t{&key :test :test-not :key :count :start :end :from-end} 3921@defun cl-substitute new old seq @t{&key :test :test-not :key :count :start :end :from-end}
3921This function returns a copy of @var{seq}, with all elements 3922This function returns a copy of @var{seq}, with all elements
3922matching @var{old} replaced with @var{new}. The @code{:count}, 3923matching @var{old} replaced with @var{new}. The @code{:count},
3923@code{:start}, @code{:end}, and @code{:from-end} arguments may be 3924@code{:start}, @code{:end}, and @code{:from-end} arguments may be
3924used to limit the number of substitutions made. 3925used to limit the number of substitutions made.
3925@end defun 3926@end defun
3926 3927
3927@defun nsubstitute new old seq @t{&key :test :test-not :key :count :start :end :from-end} 3928@defun cl-nsubstitute new old seq @t{&key :test :test-not :key :count :start :end :from-end}
3928This is a destructive version of @code{substitute}; it performs 3929This is a destructive version of @code{cl-substitute}; it performs
3929the substitution using @code{setcar} or @code{aset} rather than 3930the substitution using @code{setcar} or @code{aset} rather than
3930by returning a changed copy of the sequence. 3931by returning a changed copy of the sequence.
3931@end defun 3932@end defun
3932 3933
3933@findex substitute-if 3934@findex cl-substitute-if
3934@findex substitute-if-not 3935@findex cl-substitute-if-not
3935@findex nsubstitute-if 3936@findex cl-nsubstitute-if
3936@findex nsubstitute-if-not 3937@findex cl-nsubstitute-if-not
3937The @code{substitute-if}, @code{substitute-if-not}, @code{nsubstitute-if}, 3938The @code{cl-substitute-if}, @code{cl-substitute-if-not}, @code{cl-nsubstitute-if},
3938and @code{nsubstitute-if-not} functions are defined similarly. For 3939and @code{cl-nsubstitute-if-not} functions are defined similarly. For
3939these, a @var{predicate} is given in place of the @var{old} argument. 3940these, a @var{predicate} is given in place of the @var{old} argument.
3940 3941
3941@node Searching Sequences 3942@node Searching Sequences
@@ -3943,9 +3944,9 @@ these, a @var{predicate} is given in place of the @var{old} argument.
3943 3944
3944@noindent 3945@noindent
3945These functions search for elements or subsequences in a sequence. 3946These functions search for elements or subsequences in a sequence.
3946(See also @code{member*} and @code{assoc*}; @pxref{Lists}.) 3947(See also @code{cl-member} and @code{cl-assoc}; @pxref{Lists}.)
3947 3948
3948@defun find item seq @t{&key :test :test-not :key :start :end :from-end} 3949@defun cl-find item seq @t{&key :test :test-not :key :start :end :from-end}
3949This function searches @var{seq} for an element matching @var{item}. 3950This function searches @var{seq} for an element matching @var{item}.
3950If it finds a match, it returns the matching element. Otherwise, 3951If it finds a match, it returns the matching element. Otherwise,
3951it returns @code{nil}. It returns the leftmost match, unless 3952it returns @code{nil}. It returns the leftmost match, unless
@@ -3954,30 +3955,30 @@ match. The @code{:start} and @code{:end} arguments may be used to
3954limit the range of elements that are searched. 3955limit the range of elements that are searched.
3955@end defun 3956@end defun
3956 3957
3957@defun position item seq @t{&key :test :test-not :key :start :end :from-end} 3958@defun cl-position item seq @t{&key :test :test-not :key :start :end :from-end}
3958This function is like @code{find}, except that it returns the 3959This function is like @code{cl-find}, except that it returns the
3959integer position in the sequence of the matching item rather than 3960integer position in the sequence of the matching item rather than
3960the item itself. The position is relative to the start of the 3961the item itself. The position is relative to the start of the
3961sequence as a whole, even if @code{:start} is non-zero. The function 3962sequence as a whole, even if @code{:start} is non-zero. The function
3962returns @code{nil} if no matching element was found. 3963returns @code{nil} if no matching element was found.
3963@end defun 3964@end defun
3964 3965
3965@defun count item seq @t{&key :test :test-not :key :start :end} 3966@defun cl-count item seq @t{&key :test :test-not :key :start :end}
3966This function returns the number of elements of @var{seq} which 3967This function returns the number of elements of @var{seq} which
3967match @var{item}. The result is always a nonnegative integer. 3968match @var{item}. The result is always a nonnegative integer.
3968@end defun 3969@end defun
3969 3970
3970@findex find-if 3971@findex cl-find-if
3971@findex find-if-not 3972@findex cl-find-if-not
3972@findex position-if 3973@findex cl-position-if
3973@findex position-if-not 3974@findex cl-position-if-not
3974@findex count-if 3975@findex cl-count-if
3975@findex count-if-not 3976@findex cl-count-if-not
3976The @code{find-if}, @code{find-if-not}, @code{position-if}, 3977The @code{cl-find-if}, @code{cl-find-if-not}, @code{cl-position-if},
3977@code{position-if-not}, @code{count-if}, and @code{count-if-not} 3978@code{cl-position-if-not}, @code{cl-count-if}, and @code{cl-count-if-not}
3978functions are defined similarly. 3979functions are defined similarly.
3979 3980
3980@defun mismatch seq1 seq2 @t{&key :test :test-not :key :start1 :end1 :start2 :end2 :from-end} 3981@defun cl-mismatch seq1 seq2 @t{&key :test :test-not :key :start1 :end1 :start2 :end2 :from-end}
3981This function compares the specified parts of @var{seq1} and 3982This function compares the specified parts of @var{seq1} and
3982@var{seq2}. If they are the same length and the corresponding 3983@var{seq2}. If they are the same length and the corresponding
3983elements match (according to @code{:test}, @code{:test-not}, 3984elements match (according to @code{:test}, @code{:test-not},
@@ -3992,11 +3993,11 @@ to left starting at @code{(1- @var{end1})} and @code{(1- @var{end2})}.
3992If the sequences differ, then one plus the index of the rightmost 3993If the sequences differ, then one plus the index of the rightmost
3993difference (relative to @var{seq1}) is returned. 3994difference (relative to @var{seq1}) is returned.
3994 3995
3995An interesting example is @code{(mismatch str1 str2 :key 'upcase)}, 3996An interesting example is @code{(cl-mismatch str1 str2 :key 'upcase)},
3996which compares two strings case-insensitively. 3997which compares two strings case-insensitively.
3997@end defun 3998@end defun
3998 3999
3999@defun search seq1 seq2 @t{&key :test :test-not :key :from-end :start1 :end1 :start2 :end2} 4000@defun cl-search seq1 seq2 @t{&key :test :test-not :key :from-end :start1 :end1 :start2 :end2}
4000This function searches @var{seq2} for a subsequence that matches 4001This function searches @var{seq2} for a subsequence that matches
4001@var{seq1} (or part of it specified by @code{:start1} and 4002@var{seq1} (or part of it specified by @code{:start1} and
4002@code{:end1}.) Only matches which fall entirely within the region 4003@code{:end1}.) Only matches which fall entirely within the region
@@ -4010,7 +4011,7 @@ function finds the @emph{rightmost} matching subsequence.
4010@node Sorting Sequences 4011@node Sorting Sequences
4011@section Sorting Sequences 4012@section Sorting Sequences
4012 4013
4013@defun sort* seq predicate @t{&key :key} 4014@defun clsort seq predicate @t{&key :key}
4014This function sorts @var{seq} into increasing order as determined 4015This function sorts @var{seq} into increasing order as determined
4015by using @var{predicate} to compare pairs of elements. @var{predicate} 4016by using @var{predicate} to compare pairs of elements. @var{predicate}
4016should return true (non-@code{nil}) if and only if its first argument 4017should return true (non-@code{nil}) if and only if its first argument
@@ -4025,7 +4026,7 @@ accepts a @code{:key} argument which is used to preprocess data
4025fed to the @var{predicate} function. For example, 4026fed to the @var{predicate} function. For example,
4026 4027
4027@example 4028@example
4028(setq data (sort* data 'string-lessp :key 'downcase)) 4029(setq data (cl-sort data 'string-lessp :key 'downcase))
4029@end example 4030@end example
4030 4031
4031@noindent 4032@noindent
@@ -4035,25 +4036,25 @@ would be useful for sorting association lists. It should only be a
4035simple accessor though, it's used heavily in the current 4036simple accessor though, it's used heavily in the current
4036implementation. 4037implementation.
4037 4038
4038The @code{sort*} function is destructive; it sorts lists by actually 4039The @code{cl-sort} function is destructive; it sorts lists by actually
4039rearranging the @code{cdr} pointers in suitable fashion. 4040rearranging the @code{cdr} pointers in suitable fashion.
4040@end defun 4041@end defun
4041 4042
4042@defun stable-sort seq predicate @t{&key :key} 4043@defun cl-stable-sort seq predicate @t{&key :key}
4043This function sorts @var{seq} @dfn{stably}, meaning two elements 4044This function sorts @var{seq} @dfn{stably}, meaning two elements
4044which are equal in terms of @var{predicate} are guaranteed not to 4045which are equal in terms of @var{predicate} are guaranteed not to
4045be rearranged out of their original order by the sort. 4046be rearranged out of their original order by the sort.
4046 4047
4047In practice, @code{sort*} and @code{stable-sort} are equivalent 4048In practice, @code{cl-sort} and @code{cl-stable-sort} are equivalent
4048in Emacs Lisp because the underlying @code{sort} function is 4049in Emacs Lisp because the underlying @code{sort} function is
4049stable by default. However, this package reserves the right to 4050stable by default. However, this package reserves the right to
4050use non-stable methods for @code{sort*} in the future. 4051use non-stable methods for @code{cl-sort} in the future.
4051@end defun 4052@end defun
4052 4053
4053@defun merge type seq1 seq2 predicate @t{&key :key} 4054@defun cl-merge type seq1 seq2 predicate @t{&key :key}
4054This function merges two sequences @var{seq1} and @var{seq2} by 4055This function merges two sequences @var{seq1} and @var{seq2} by
4055interleaving their elements. The result sequence, of type @var{type} 4056interleaving their elements. The result sequence, of type @var{type}
4056(in the sense of @code{concatenate}), has length equal to the sum 4057(in the sense of @code{cl-concatenate}), has length equal to the sum
4057of the lengths of the two input sequences. The sequences may be 4058of the lengths of the two input sequences. The sequences may be
4058modified destructively. Order of elements within @var{seq1} and 4059modified destructively. Order of elements within @var{seq1} and
4059@var{seq2} is preserved in the interleaving; elements of the two 4060@var{seq2} is preserved in the interleaving; elements of the two
@@ -4073,10 +4074,10 @@ a merged sequence which is (stably) sorted according to
4073The functions described here operate on lists. 4074The functions described here operate on lists.
4074 4075
4075@menu 4076@menu
4076* List Functions:: @code{caddr}, @code{first}, @code{list*}, etc. 4077* List Functions:: @code{cl-caddr}, @code{cl-first}, @code{cl-list*}, etc.
4077* Substitution of Expressions:: @code{subst}, @code{sublis}, etc. 4078* Substitution of Expressions:: @code{cl-subst}, @code{cl-sublis}, etc.
4078* Lists as Sets:: @code{member*}, @code{adjoin}, @code{union}, etc. 4079* Lists as Sets:: @code{cl-member}, @code{cl-adjoin}, @code{cl-union}, etc.
4079* Association Lists:: @code{assoc*}, @code{rassoc*}, @code{acons}, @code{pairlis}. 4080* Association Lists:: @code{cl-assoc}, @code{cl-rassoc}, @code{cl-acons}, @code{cl-pairlis}.
4080@end menu 4081@end menu
4081 4082
4082@node List Functions 4083@node List Functions
@@ -4086,7 +4087,7 @@ The functions described here operate on lists.
4086This section describes a number of simple operations on lists, 4087This section describes a number of simple operations on lists,
4087i.e., chains of cons cells. 4088i.e., chains of cons cells.
4088 4089
4089@defun caddr x 4090@defun cl-caddr x
4090This function is equivalent to @code{(car (cdr (cdr @var{x})))}. 4091This function is equivalent to @code{(car (cdr (cdr @var{x})))}.
4091Likewise, this package defines all 28 @code{c@var{xxx}r} functions 4092Likewise, this package defines all 28 @code{c@var{xxx}r} functions
4092where @var{xxx} is up to four @samp{a}s and/or @samp{d}s. 4093where @var{xxx} is up to four @samp{a}s and/or @samp{d}s.
@@ -4094,24 +4095,24 @@ All of these functions are @code{setf}-able, and calls to them
4094are expanded inline by the byte-compiler for maximum efficiency. 4095are expanded inline by the byte-compiler for maximum efficiency.
4095@end defun 4096@end defun
4096 4097
4097@defun first x 4098@defun cl-first x
4098This function is a synonym for @code{(car @var{x})}. Likewise, 4099This function is a synonym for @code{(car @var{x})}. Likewise,
4099the functions @code{second}, @code{third}, @dots{}, through 4100the functions @code{cl-second}, @code{cl-third}, @dots{}, through
4100@code{tenth} return the given element of the list @var{x}. 4101@code{cl-tenth} return the given element of the list @var{x}.
4101@end defun 4102@end defun
4102 4103
4103@defun rest x 4104@defun cl-rest x
4104This function is a synonym for @code{(cdr @var{x})}. 4105This function is a synonym for @code{(cdr @var{x})}.
4105@end defun 4106@end defun
4106 4107
4107@defun endp x 4108@defun cl-endp x
4108Common Lisp defines this function to act like @code{null}, but 4109Common Lisp defines this function to act like @code{null}, but
4109signaling an error if @code{x} is neither a @code{nil} nor a 4110signaling an error if @code{x} is neither a @code{nil} nor a
4110cons cell. This package simply defines @code{endp} as a synonym 4111cons cell. This package simply defines @code{cl-endp} as a synonym
4111for @code{null}. 4112for @code{null}.
4112@end defun 4113@end defun
4113 4114
4114@defun list-length x 4115@defun cl-list-length x
4115This function returns the length of list @var{x}, exactly like 4116This function returns the length of list @var{x}, exactly like
4116@code{(length @var{x})}, except that if @var{x} is a circular 4117@code{(length @var{x})}, except that if @var{x} is a circular
4117list (where the cdr-chain forms a loop rather than terminating 4118list (where the cdr-chain forms a loop rather than terminating
@@ -4119,38 +4120,35 @@ with @code{nil}), this function returns @code{nil}. (The regular
4119@code{length} function would get stuck if given a circular list.) 4120@code{length} function would get stuck if given a circular list.)
4120@end defun 4121@end defun
4121 4122
4122@defun list* arg &rest others 4123@defun cl-list* arg &rest others
4123This function constructs a list of its arguments. The final 4124This function constructs a list of its arguments. The final
4124argument becomes the @code{cdr} of the last cell constructed. 4125argument becomes the @code{cdr} of the last cell constructed.
4125Thus, @code{(list* @var{a} @var{b} @var{c})} is equivalent to 4126Thus, @code{(cl-list* @var{a} @var{b} @var{c})} is equivalent to
4126@code{(cons @var{a} (cons @var{b} @var{c}))}, and 4127@code{(cons @var{a} (cons @var{b} @var{c}))}, and
4127@code{(list* @var{a} @var{b} nil)} is equivalent to 4128@code{(cl-list* @var{a} @var{b} nil)} is equivalent to
4128@code{(list @var{a} @var{b})}. 4129@code{(list @var{a} @var{b})}.
4129
4130(Note that this function really is called @code{list*} in Common
4131Lisp; it is not a name invented for this package like @code{member*}
4132or @code{defun*}.)
4133@end defun 4130@end defun
4134 4131
4135@defun ldiff list sublist 4132@defun cl-ldiff list sublist
4136If @var{sublist} is a sublist of @var{list}, i.e., is @code{eq} to 4133If @var{sublist} is a sublist of @var{list}, i.e., is @code{eq} to
4137one of the cons cells of @var{list}, then this function returns 4134one of the cons cells of @var{list}, then this function returns
4138a copy of the part of @var{list} up to but not including 4135a copy of the part of @var{list} up to but not including
4139@var{sublist}. For example, @code{(ldiff x (cddr x))} returns 4136@var{sublist}. For example, @code{(cl-ldiff x (cddr x))} returns
4140the first two elements of the list @code{x}. The result is a 4137the first two elements of the list @code{x}. The result is a
4141copy; the original @var{list} is not modified. If @var{sublist} 4138copy; the original @var{list} is not modified. If @var{sublist}
4142is not a sublist of @var{list}, a copy of the entire @var{list} 4139is not a sublist of @var{list}, a copy of the entire @var{list}
4143is returned. 4140is returned.
4144@end defun 4141@end defun
4145 4142
4146@defun copy-list list 4143@defun cl-copy-list list
4147This function returns a copy of the list @var{list}. It copies 4144This function returns a copy of the list @var{list}. It copies
4148dotted lists like @code{(1 2 . 3)} correctly. 4145dotted lists like @code{(1 2 . 3)} correctly.
4149@end defun 4146@end defun
4150 4147
4151@defun copy-tree x &optional vecp 4148@defun copy-tree x &optional vecp
4152This function returns a copy of the tree of cons cells @var{x}. 4149This function returns a copy of the tree of cons cells @var{x}.
4153Unlike @code{copy-sequence} (and its alias @code{copy-list}), 4150@c FIXME? cl-copy-list is not an alias of copy-sequence.
4151Unlike @code{copy-sequence} (and its alias @code{cl-copy-list}),
4154which copies only along the @code{cdr} direction, this function 4152which copies only along the @code{cdr} direction, this function
4155copies (recursively) along both the @code{car} and the @code{cdr} 4153copies (recursively) along both the @code{car} and the @code{cdr}
4156directions. If @var{x} is not a cons cell, the function simply 4154directions. If @var{x} is not a cons cell, the function simply
@@ -4159,7 +4157,7 @@ is true, this function copies vectors (recursively) as well as
4159cons cells. 4157cons cells.
4160@end defun 4158@end defun
4161 4159
4162@defun tree-equal x y @t{&key :test :test-not :key} 4160@defun cl-tree-equal x y @t{&key :test :test-not :key}
4163This function compares two trees of cons cells. If @var{x} and 4161This function compares two trees of cons cells. If @var{x} and
4164@var{y} are both cons cells, their @code{car}s and @code{cdr}s are 4162@var{y} are both cons cells, their @code{car}s and @code{cdr}s are
4165compared recursively. If neither @var{x} nor @var{y} is a cons 4163compared recursively. If neither @var{x} nor @var{y} is a cons
@@ -4177,10 +4175,10 @@ applied to the elements of both trees. @xref{Sequences}.
4177 4175
4178@noindent 4176@noindent
4179These functions substitute elements throughout a tree of cons 4177These functions substitute elements throughout a tree of cons
4180cells. (@xref{Sequence Functions}, for the @code{substitute} 4178cells. (@xref{Sequence Functions}, for the @code{cl-substitute}
4181function, which works on just the top-level elements of a list.) 4179function, which works on just the top-level elements of a list.)
4182 4180
4183@defun subst new old tree @t{&key :test :test-not :key} 4181@defun cl-subst new old tree @t{&key :test :test-not :key}
4184This function substitutes occurrences of @var{old} with @var{new} 4182This function substitutes occurrences of @var{old} with @var{new}
4185in @var{tree}, a tree of cons cells. It returns a substituted 4183in @var{tree}, a tree of cons cells. It returns a substituted
4186tree, which will be a copy except that it may share storage with 4184tree, which will be a copy except that it may share storage with
@@ -4195,21 +4193,21 @@ The @code{:key} function is applied to the elements of the tree
4195but not to @var{old}. 4193but not to @var{old}.
4196@end defun 4194@end defun
4197 4195
4198@defun nsubst new old tree @t{&key :test :test-not :key} 4196@defun cl-nsubst new old tree @t{&key :test :test-not :key}
4199This function is like @code{subst}, except that it works by 4197This function is like @code{cl-subst}, except that it works by
4200destructive modification (by @code{setcar} or @code{setcdr}) 4198destructive modification (by @code{setcar} or @code{setcdr})
4201rather than copying. 4199rather than copying.
4202@end defun 4200@end defun
4203 4201
4204@findex subst-if 4202@findex cl-subst-if
4205@findex subst-if-not 4203@findex cl-subst-if-not
4206@findex nsubst-if 4204@findex cl-nsubst-if
4207@findex nsubst-if-not 4205@findex cl-nsubst-if-not
4208The @code{subst-if}, @code{subst-if-not}, @code{nsubst-if}, and 4206The @code{cl-subst-if}, @code{cl-subst-if-not}, @code{cl-nsubst-if}, and
4209@code{nsubst-if-not} functions are defined similarly. 4207@code{cl-nsubst-if-not} functions are defined similarly.
4210 4208
4211@defun sublis alist tree @t{&key :test :test-not :key} 4209@defun cl-sublis alist tree @t{&key :test :test-not :key}
4212This function is like @code{subst}, except that it takes an 4210This function is like @code{cl-subst}, except that it takes an
4213association list @var{alist} of @var{old}-@var{new} pairs. 4211association list @var{alist} of @var{old}-@var{new} pairs.
4214Each element of the tree (after applying the @code{:key} 4212Each element of the tree (after applying the @code{:key}
4215function, if any), is compared with the @code{car}s of 4213function, if any), is compared with the @code{car}s of
@@ -4217,8 +4215,8 @@ function, if any), is compared with the @code{car}s of
4217@code{cdr}. 4215@code{cdr}.
4218@end defun 4216@end defun
4219 4217
4220@defun nsublis alist tree @t{&key :test :test-not :key} 4218@defun cl-nsublis alist tree @t{&key :test :test-not :key}
4221This is a destructive version of @code{sublis}. 4219This is a destructive version of @code{cl-sublis}.
4222@end defun 4220@end defun
4223 4221
4224@node Lists as Sets 4222@node Lists as Sets
@@ -4228,7 +4226,7 @@ This is a destructive version of @code{sublis}.
4228These functions perform operations on lists which represent sets 4226These functions perform operations on lists which represent sets
4229of elements. 4227of elements.
4230 4228
4231@defun member* item list @t{&key :test :test-not :key} 4229@defun cl-member item list @t{&key :test :test-not :key}
4232This function searches @var{list} for an element matching @var{item}. 4230This function searches @var{list} for an element matching @var{item}.
4233If a match is found, it returns the cons cell whose @code{car} was 4231If a match is found, it returns the cons cell whose @code{car} was
4234the matching element. Otherwise, it returns @code{nil}. Elements 4232the matching element. Otherwise, it returns @code{nil}. Elements
@@ -4236,34 +4234,33 @@ are compared by @code{eql} by default; you can use the @code{:test},
4236@code{:test-not}, and @code{:key} arguments to modify this behavior. 4234@code{:test-not}, and @code{:key} arguments to modify this behavior.
4237@xref{Sequences}. 4235@xref{Sequences}.
4238 4236
4239Note that this function's name is suffixed by @samp{*} to avoid 4237The standard Emacs lisp function @code{member} uses @code{equal} for
4240the incompatible @code{member} function defined in Emacs. 4238comparisons; it is equivalent to @code{(cl-member @var{item} @var{list}
4241(That function uses @code{equal} for comparisons; it is equivalent 4239:test 'equal)}.
4242to @code{(member* @var{item} @var{list} :test 'equal)}.)
4243@end defun 4240@end defun
4244 4241
4245@findex member-if 4242@findex cl-member-if
4246@findex member-if-not 4243@findex cl-member-if-not
4247The @code{member-if} and @code{member-if-not} functions 4244The @code{cl-member-if} and @code{cl-member-if-not} functions
4248analogously search for elements which satisfy a given predicate. 4245analogously search for elements which satisfy a given predicate.
4249 4246
4250@defun tailp sublist list 4247@defun cl-tailp sublist list
4251This function returns @code{t} if @var{sublist} is a sublist of 4248This function returns @code{t} if @var{sublist} is a sublist of
4252@var{list}, i.e., if @var{sublist} is @code{eql} to @var{list} or to 4249@var{list}, i.e., if @var{sublist} is @code{eql} to @var{list} or to
4253any of its @code{cdr}s. 4250any of its @code{cdr}s.
4254@end defun 4251@end defun
4255 4252
4256@defun adjoin item list @t{&key :test :test-not :key} 4253@defun cl-adjoin item list @t{&key :test :test-not :key}
4257This function conses @var{item} onto the front of @var{list}, 4254This function conses @var{item} onto the front of @var{list},
4258like @code{(cons @var{item} @var{list})}, but only if @var{item} 4255like @code{(cons @var{item} @var{list})}, but only if @var{item}
4259is not already present on the list (as determined by @code{member*}). 4256is not already present on the list (as determined by @code{cl-member}).
4260If a @code{:key} argument is specified, it is applied to 4257If a @code{:key} argument is specified, it is applied to
4261@var{item} as well as to the elements of @var{list} during 4258@var{item} as well as to the elements of @var{list} during
4262the search, on the reasoning that @var{item} is ``about'' to 4259the search, on the reasoning that @var{item} is ``about'' to
4263become part of the list. 4260become part of the list.
4264@end defun 4261@end defun
4265 4262
4266@defun union list1 list2 @t{&key :test :test-not :key} 4263@defun cl-union list1 list2 @t{&key :test :test-not :key}
4267This function combines two lists which represent sets of items, 4264This function combines two lists which represent sets of items,
4268returning a list that represents the union of those two sets. 4265returning a list that represents the union of those two sets.
4269The result list will contain all items which appear in @var{list1} 4266The result list will contain all items which appear in @var{list1}
@@ -4275,46 +4272,46 @@ result list. The order of elements in the result list is also
4275undefined. 4272undefined.
4276@end defun 4273@end defun
4277 4274
4278@defun nunion list1 list2 @t{&key :test :test-not :key} 4275@defun cl-nunion list1 list2 @t{&key :test :test-not :key}
4279This is a destructive version of @code{union}; rather than copying, 4276This is a destructive version of @code{cl-union}; rather than copying,
4280it tries to reuse the storage of the argument lists if possible. 4277it tries to reuse the storage of the argument lists if possible.
4281@end defun 4278@end defun
4282 4279
4283@defun intersection list1 list2 @t{&key :test :test-not :key} 4280@defun cl-intersection list1 list2 @t{&key :test :test-not :key}
4284This function computes the intersection of the sets represented 4281This function computes the intersection of the sets represented
4285by @var{list1} and @var{list2}. It returns the list of items 4282by @var{list1} and @var{list2}. It returns the list of items
4286which appear in both @var{list1} and @var{list2}. 4283which appear in both @var{list1} and @var{list2}.
4287@end defun 4284@end defun
4288 4285
4289@defun nintersection list1 list2 @t{&key :test :test-not :key} 4286@defun cl-nintersection list1 list2 @t{&key :test :test-not :key}
4290This is a destructive version of @code{intersection}. It 4287This is a destructive version of @code{cl-intersection}. It
4291tries to reuse storage of @var{list1} rather than copying. 4288tries to reuse storage of @var{list1} rather than copying.
4292It does @emph{not} reuse the storage of @var{list2}. 4289It does @emph{not} reuse the storage of @var{list2}.
4293@end defun 4290@end defun
4294 4291
4295@defun set-difference list1 list2 @t{&key :test :test-not :key} 4292@defun cl-set-difference list1 list2 @t{&key :test :test-not :key}
4296This function computes the ``set difference'' of @var{list1} 4293This function computes the ``set difference'' of @var{list1}
4297and @var{list2}, i.e., the set of elements that appear in 4294and @var{list2}, i.e., the set of elements that appear in
4298@var{list1} but @emph{not} in @var{list2}. 4295@var{list1} but @emph{not} in @var{list2}.
4299@end defun 4296@end defun
4300 4297
4301@defun nset-difference list1 list2 @t{&key :test :test-not :key} 4298@defun cl-nset-difference list1 list2 @t{&key :test :test-not :key}
4302This is a destructive @code{set-difference}, which will try 4299This is a destructive @code{cl-set-difference}, which will try
4303to reuse @var{list1} if possible. 4300to reuse @var{list1} if possible.
4304@end defun 4301@end defun
4305 4302
4306@defun set-exclusive-or list1 list2 @t{&key :test :test-not :key} 4303@defun cl-set-exclusive-or list1 list2 @t{&key :test :test-not :key}
4307This function computes the ``set exclusive or'' of @var{list1} 4304This function computes the ``set exclusive or'' of @var{list1}
4308and @var{list2}, i.e., the set of elements that appear in 4305and @var{list2}, i.e., the set of elements that appear in
4309exactly one of @var{list1} and @var{list2}. 4306exactly one of @var{list1} and @var{list2}.
4310@end defun 4307@end defun
4311 4308
4312@defun nset-exclusive-or list1 list2 @t{&key :test :test-not :key} 4309@defun cl-nset-exclusive-or list1 list2 @t{&key :test :test-not :key}
4313This is a destructive @code{set-exclusive-or}, which will try 4310This is a destructive @code{cl-set-exclusive-or}, which will try
4314to reuse @var{list1} and @var{list2} if possible. 4311to reuse @var{list1} and @var{list2} if possible.
4315@end defun 4312@end defun
4316 4313
4317@defun subsetp list1 list2 @t{&key :test :test-not :key} 4314@defun cl-subsetp list1 list2 @t{&key :test :test-not :key}
4318This function checks whether @var{list1} represents a subset 4315This function checks whether @var{list1} represents a subset
4319of @var{list2}, i.e., whether every element of @var{list1} 4316of @var{list2}, i.e., whether every element of @var{list1}
4320also appears in @var{list2}. 4317also appears in @var{list2}.
@@ -4328,7 +4325,7 @@ An @dfn{association list} is a list representing a mapping from
4328one set of values to another; any list whose elements are cons 4325one set of values to another; any list whose elements are cons
4329cells is an association list. 4326cells is an association list.
4330 4327
4331@defun assoc* item a-list @t{&key :test :test-not :key} 4328@defun cl-assoc item a-list @t{&key :test :test-not :key}
4332This function searches the association list @var{a-list} for an 4329This function searches the association list @var{a-list} for an
4333element whose @code{car} matches (in the sense of @code{:test}, 4330element whose @code{car} matches (in the sense of @code{:test},
4334@code{:test-not}, and @code{:key}, or by comparison with @code{eql}) 4331@code{:test-not}, and @code{:key}, or by comparison with @code{eql})
@@ -4340,27 +4337,27 @@ are not cons cells. (This corresponds to the behavior of
4340elements of @var{a-list} to be an error.) 4337elements of @var{a-list} to be an error.)
4341@end defun 4338@end defun
4342 4339
4343@defun rassoc* item a-list @t{&key :test :test-not :key} 4340@defun cl-rassoc item a-list @t{&key :test :test-not :key}
4344This function searches for an element whose @code{cdr} matches 4341This function searches for an element whose @code{cdr} matches
4345@var{item}. If @var{a-list} represents a mapping, this applies 4342@var{item}. If @var{a-list} represents a mapping, this applies
4346the inverse of the mapping to @var{item}. 4343the inverse of the mapping to @var{item}.
4347@end defun 4344@end defun
4348 4345
4349@findex assoc-if 4346@findex cl-assoc-if
4350@findex assoc-if-not 4347@findex cl-assoc-if-not
4351@findex rassoc-if 4348@findex cl-rassoc-if
4352@findex rassoc-if-not 4349@findex cl-rassoc-if-not
4353The @code{assoc-if}, @code{assoc-if-not}, @code{rassoc-if}, 4350The @code{cl-assoc-if}, @code{cl-assoc-if-not}, @code{cl-rassoc-if},
4354and @code{rassoc-if-not} functions are defined similarly. 4351and @code{cl-rassoc-if-not} functions are defined similarly.
4355 4352
4356Two simple functions for constructing association lists are: 4353Two simple functions for constructing association lists are:
4357 4354
4358@defun acons key value alist 4355@defun cl-acons key value alist
4359This is equivalent to @code{(cons (cons @var{key} @var{value}) @var{alist})}. 4356This is equivalent to @code{(cons (cons @var{key} @var{value}) @var{alist})}.
4360@end defun 4357@end defun
4361 4358
4362@defun pairlis keys values &optional alist 4359@defun cl-pairlis keys values &optional alist
4363This is equivalent to @code{(nconc (mapcar* 'cons @var{keys} @var{values}) 4360This is equivalent to @code{(nconc (cl-mapcar 'cons @var{keys} @var{values})
4364@var{alist})}. 4361@var{alist})}.
4365@end defun 4362@end defun
4366 4363
@@ -4382,15 +4379,15 @@ system provides no way to create new distinct types, this package
4382implements structures as vectors (or lists upon request) with a 4379implements structures as vectors (or lists upon request) with a
4383special ``tag'' symbol to identify them. 4380special ``tag'' symbol to identify them.
4384 4381
4385@defspec defstruct name slots@dots{} 4382@defspec cl-defstruct name slots@dots{}
4386The @code{defstruct} form defines a new structure type called 4383The @code{cl-defstruct} form defines a new structure type called
4387@var{name}, with the specified @var{slots}. (The @var{slots} 4384@var{name}, with the specified @var{slots}. (The @var{slots}
4388may begin with a string which documents the structure type.) 4385may begin with a string which documents the structure type.)
4389In the simplest case, @var{name} and each of the @var{slots} 4386In the simplest case, @var{name} and each of the @var{slots}
4390are symbols. For example, 4387are symbols. For example,
4391 4388
4392@example 4389@example
4393(defstruct person name age sex) 4390(cl-defstruct person name age sex)
4394@end example 4391@end example
4395 4392
4396@noindent 4393@noindent
@@ -4401,7 +4398,7 @@ and @code{(person-sex @var{p})}. You can also change these slots by
4401using @code{setf} on any of these place forms: 4398using @code{setf} on any of these place forms:
4402 4399
4403@example 4400@example
4404(incf (person-age birthday-boy)) 4401(cl-incf (person-age birthday-boy))
4405@end example 4402@end example
4406 4403
4407You can create a new @code{person} by calling @code{make-person}, 4404You can create a new @code{person} by calling @code{make-person},
@@ -4465,10 +4462,10 @@ the slot's value is determined when the object is created and does
4465not change afterward. 4462not change afterward.
4466 4463
4467@example 4464@example
4468(defstruct person 4465(cl-defstruct person
4469 (name nil :read-only t) 4466 (name nil :read-only t)
4470 age 4467 age
4471 (sex 'unknown)) 4468 (sex 'unknown))
4472@end example 4469@end example
4473 4470
4474Any slot options other than @code{:read-only} are ignored. 4471Any slot options other than @code{:read-only} are ignored.
@@ -4480,10 +4477,10 @@ by arguments. (By contrast, slot options are key-value pairs not
4480enclosed in lists.) 4477enclosed in lists.)
4481 4478
4482@example 4479@example
4483(defstruct (person (:constructor create-person) 4480(cl-defstruct (person (:constructor create-person)
4484 (:type list) 4481 (:type list)
4485 :named) 4482 :named)
4486 name age sex) 4483 name age sex)
4487@end example 4484@end example
4488 4485
4489The following structure options are recognized. 4486The following structure options are recognized.
@@ -4529,15 +4526,15 @@ as well unless you disable it with a simple-format @code{:constructor}
4529option. 4526option.
4530 4527
4531@example 4528@example
4532(defstruct 4529(cl-defstruct
4533 (person 4530 (person
4534 (:constructor nil) ; no default constructor 4531 (:constructor nil) ; no default constructor
4535 (:constructor new-person (name sex &optional (age 0))) 4532 (:constructor new-person (name sex &optional (age 0)))
4536 (:constructor new-hound (&key (name "Rover") 4533 (:constructor new-hound (&key (name "Rover")
4537 (dog-years 0) 4534 (dog-years 0)
4538 &aux (age (* 7 dog-years)) 4535 &aux (age (* 7 dog-years))
4539 (sex 'canine)))) 4536 (sex 'canine))))
4540 name age sex) 4537 name age sex)
4541@end example 4538@end example
4542 4539
4543The first constructor here takes its arguments positionally rather 4540The first constructor here takes its arguments positionally rather
@@ -4576,7 +4573,7 @@ only if they used the default predicate name.
4576@item :include 4573@item :include
4577This option implements a very limited form of C++-style inheritance. 4574This option implements a very limited form of C++-style inheritance.
4578The argument is the name of another structure type previously 4575The argument is the name of another structure type previously
4579created with @code{defstruct}. The effect is to cause the new 4576created with @code{cl-defstruct}. The effect is to cause the new
4580structure type to inherit all of the included structure's slots 4577structure type to inherit all of the included structure's slots
4581(plus, of course, any new slots described by this struct's slot 4578(plus, of course, any new slots described by this struct's slot
4582descriptors). The new structure is considered a ``specialization'' 4579descriptors). The new structure is considered a ``specialization''
@@ -4589,12 +4586,12 @@ slot descriptors for slots in the included structure, possibly with
4589modified default values. Borrowing an example from Steele: 4586modified default values. Borrowing an example from Steele:
4590 4587
4591@example 4588@example
4592(defstruct person name (age 0) sex) 4589(cl-defstruct person name (age 0) sex)
4593 @result{} person 4590 @result{} person
4594(defstruct (astronaut (:include person (age 45))) 4591(cl-defstruct (astronaut (:include person (age 45)))
4595 helmet-size 4592 helmet-size
4596 (favorite-beverage 'tang)) 4593 (favorite-beverage 'tang))
4597 @result{} astronaut 4594 @result{} astronaut
4598 4595
4599(setq joe (make-person :name "Joe")) 4596(setq joe (make-person :name "Joe"))
4600 @result{} [cl-struct-person "Joe" 0 nil] 4597 @result{} [cl-struct-person "Joe" 0 nil]
@@ -4650,9 +4647,9 @@ use named vectors. Therefore, @code{:named} is only useful in
4650conjunction with @code{:type}. 4647conjunction with @code{:type}.
4651 4648
4652@example 4649@example
4653(defstruct (person1) name age sex) 4650(cl-defstruct (person1) name age sex)
4654(defstruct (person2 (:type list) :named) name age sex) 4651(cl-defstruct (person2 (:type list) :named) name age sex)
4655(defstruct (person3 (:type list)) name age sex) 4652(cl-defstruct (person3 (:type list)) name age sex)
4656 4653
4657(setq p1 (make-person1)) 4654(setq p1 (make-person1))
4658 @result{} [cl-struct-person1 nil nil nil] 4655 @result{} [cl-struct-person1 nil nil nil]
@@ -4669,7 +4666,7 @@ conjunction with @code{:type}.
4669 @result{} error: function person3-p undefined 4666 @result{} error: function person3-p undefined
4670@end example 4667@end example
4671 4668
4672Since unnamed structures don't have tags, @code{defstruct} is not 4669Since unnamed structures don't have tags, @code{cl-defstruct} is not
4673able to make a useful predicate for recognizing them. Also, 4670able to make a useful predicate for recognizing them. Also,
4674accessors like @code{person3-name} will be generated but they 4671accessors like @code{person3-name} will be generated but they
4675will not be able to do any type checking. The @code{person3-name} 4672will not be able to do any type checking. The @code{person3-name}
@@ -4691,7 +4688,7 @@ of the included type and the first new slot.
4691@end table 4688@end table
4692@end defspec 4689@end defspec
4693 4690
4694Except as noted, the @code{defstruct} facility of this package is 4691Except as noted, the @code{cl-defstruct} facility of this package is
4695entirely compatible with that of Common Lisp. 4692entirely compatible with that of Common Lisp.
4696 4693
4697@node Assertions 4694@node Assertions
@@ -4708,10 +4705,10 @@ If the optimization property @code{speed} has been set to 3, and
4708away the following assertions. Because assertions might be optimized 4705away the following assertions. Because assertions might be optimized
4709away, it is a bad idea for them to include side-effects. 4706away, it is a bad idea for them to include side-effects.
4710 4707
4711@defspec assert test-form [show-args string args@dots{}] 4708@defspec cl-assert test-form [show-args string args@dots{}]
4712This form verifies that @var{test-form} is true (i.e., evaluates to 4709This form verifies that @var{test-form} is true (i.e., evaluates to
4713a non-@code{nil} value). If so, it returns @code{nil}. If the test 4710a non-@code{nil} value). If so, it returns @code{nil}. If the test
4714is not satisfied, @code{assert} signals an error. 4711is not satisfied, @code{cl-assert} signals an error.
4715 4712
4716A default error message will be supplied which includes @var{test-form}. 4713A default error message will be supplied which includes @var{test-form}.
4717You can specify a different error message by including a @var{string} 4714You can specify a different error message by including a @var{string}
@@ -4724,7 +4721,7 @@ will also include all non-constant arguments of the top-level
4724@var{form}. For example: 4721@var{form}. For example:
4725 4722
4726@example 4723@example
4727(assert (> x 10) t "x is too small: %d") 4724(cl-assert (> x 10) t "x is too small: %d")
4728@end example 4725@end example
4729 4726
4730This usage of @var{show-args} is an extension to Common Lisp. In 4727This usage of @var{show-args} is an extension to Common Lisp. In
@@ -4734,16 +4731,16 @@ error. Since Emacs Lisp does not support continuable errors, it
4734makes no sense to specify @var{places}. 4731makes no sense to specify @var{places}.
4735@end defspec 4732@end defspec
4736 4733
4737@defspec check-type form type [string] 4734@defspec cl-check-type form type [string]
4738This form verifies that @var{form} evaluates to a value of type 4735This form verifies that @var{form} evaluates to a value of type
4739@var{type}. If so, it returns @code{nil}. If not, @code{check-type} 4736@var{type}. If so, it returns @code{nil}. If not, @code{cl-check-type}
4740signals a @code{wrong-type-argument} error. The default error message 4737signals a @code{wrong-type-argument} error. The default error message
4741lists the erroneous value along with @var{type} and @var{form} 4738lists the erroneous value along with @var{type} and @var{form}
4742themselves. If @var{string} is specified, it is included in the 4739themselves. If @var{string} is specified, it is included in the
4743error message in place of @var{type}. For example: 4740error message in place of @var{type}. For example:
4744 4741
4745@example 4742@example
4746(check-type x (integer 1 *) "a positive integer") 4743(cl-check-type x (integer 1 *) "a positive integer")
4747@end example 4744@end example
4748 4745
4749@xref{Type Predicates}, for a description of the type specifiers 4746@xref{Type Predicates}, for a description of the type specifiers
@@ -4757,6 +4754,7 @@ user to modify @var{place}.
4757 4754
4758The following error-related macro is also defined: 4755The following error-related macro is also defined:
4759 4756
4757@c FIXME standard for some time.
4760@defspec ignore-errors forms@dots{} 4758@defspec ignore-errors forms@dots{}
4761This executes @var{forms} exactly like a @code{progn}, except that 4759This executes @var{forms} exactly like a @code{progn}, except that
4762errors are ignored during the @var{forms}. More precisely, if 4760errors are ignored during the @var{forms}. More precisely, if
@@ -4772,14 +4770,14 @@ returns the result of the last @var{form}.
4772@appendixsec Macros 4770@appendixsec Macros
4773 4771
4774@noindent 4772@noindent
4775Many of the advanced features of this package, such as @code{defun*}, 4773Many of the advanced features of this package, such as @code{cl-defun},
4776@code{loop}, and @code{setf}, are implemented as Lisp macros. In 4774@code{cl-loop}, and @code{setf}, are implemented as Lisp macros. In
4777byte-compiled code, these complex notations will be expanded into 4775byte-compiled code, these complex notations will be expanded into
4778equivalent Lisp code which is simple and efficient. For example, 4776equivalent Lisp code which is simple and efficient. For example,
4779the forms 4777the forms
4780 4778
4781@example 4779@example
4782(incf i n) 4780(cl-incf i n)
4783(push x (car p)) 4781(push x (car p))
4784@end example 4782@end example
4785 4783
@@ -4794,13 +4792,13 @@ are expanded at compile-time to the Lisp forms
4794@noindent 4792@noindent
4795which are the most efficient ways of doing these respective operations 4793which are the most efficient ways of doing these respective operations
4796in Lisp. Thus, there is no performance penalty for using the more 4794in Lisp. Thus, there is no performance penalty for using the more
4797readable @code{incf} and @code{push} forms in your compiled code. 4795readable @code{cl-incf} and @code{push} forms in your compiled code.
4798 4796
4799@emph{Interpreted} code, on the other hand, must expand these macros 4797@emph{Interpreted} code, on the other hand, must expand these macros
4800every time they are executed. For this reason it is strongly 4798every time they are executed. For this reason it is strongly
4801recommended that code making heavy use of macros be compiled. 4799recommended that code making heavy use of macros be compiled.
4802(The features labeled ``Special Form'' instead of ``Function'' in 4800(The features labeled ``Special Form'' instead of ``Function'' in
4803this manual are macros.) A loop using @code{incf} a hundred times 4801this manual are macros.) A loop using @code{cl-incf} a hundred times
4804will execute considerably faster if compiled, and will also 4802will execute considerably faster if compiled, and will also
4805garbage-collect less because the macro expansion will not have 4803garbage-collect less because the macro expansion will not have
4806to be generated, used, and thrown away a hundred times. 4804to be generated, used, and thrown away a hundred times.
@@ -4824,36 +4822,36 @@ and type @kbd{C-x C-e} immediately after the closing parenthesis;
4824the expansion 4822the expansion
4825 4823
4826@example 4824@example
4827(block nil 4825(cl-block nil
4828 (let* ((x 0) 4826 (let* ((x 0)
4829 (G1004 nil)) 4827 (G1004 nil))
4830 (while (< x 10) 4828 (while (< x 10)
4831 (setq G1004 (cons x G1004)) 4829 (setq G1004 (cons x G1004))
4832 (setq x (+ x 1))) 4830 (setq x (+ x 1)))
4833 (nreverse G1004))) 4831 (nreverse G1004)))
4834@end example 4832@end example
4835 4833
4836@noindent 4834@noindent
4837will be inserted into the buffer. (The @code{block} macro is 4835will be inserted into the buffer. (The @code{cl-block} macro is
4838expanded differently in the interpreter and compiler, so 4836expanded differently in the interpreter and compiler, so
4839@code{cl-prettyexpand} just leaves it alone. The temporary 4837@code{cl-prettyexpand} just leaves it alone. The temporary
4840variable @code{G1004} was created by @code{gensym}.) 4838variable @code{G1004} was created by @code{cl-gensym}.)
4841 4839
4842If the optional argument @var{full} is true, then @emph{all} 4840If the optional argument @var{full} is true, then @emph{all}
4843macros are expanded, including @code{block}, @code{eval-when}, 4841macros are expanded, including @code{cl-block}, @code{cl-eval-when},
4844and compiler macros. Expansion is done as if @var{form} were 4842and compiler macros. Expansion is done as if @var{form} were
4845a top-level form in a file being compiled. For example, 4843a top-level form in a file being compiled. For example,
4846 4844
4847@example 4845@example
4848(cl-prettyexpand '(pushnew 'x list)) 4846(cl-prettyexpand '(cl-pushnew 'x list))
4849 @print{} (setq list (adjoin 'x list)) 4847 @print{} (setq list (cl-adjoin 'x list))
4850(cl-prettyexpand '(pushnew 'x list) t) 4848(cl-prettyexpand '(cl-pushnew 'x list) t)
4851 @print{} (setq list (if (memq 'x list) list (cons 'x list))) 4849 @print{} (setq list (if (memq 'x list) list (cons 'x list)))
4852(cl-prettyexpand '(caddr (member* 'a list)) t) 4850(cl-prettyexpand '(caddr (cl-member 'a list)) t)
4853 @print{} (car (cdr (cdr (memq 'a list)))) 4851 @print{} (car (cdr (cdr (memq 'a list))))
4854@end example 4852@end example
4855 4853
4856Note that @code{adjoin}, @code{caddr}, and @code{member*} all 4854Note that @code{cl-adjoin}, @code{cl-caddr}, and @code{cl-member} all
4857have built-in compiler macros to optimize them in common cases. 4855have built-in compiler macros to optimize them in common cases.
4858@end defun 4856@end defun
4859 4857
@@ -4875,22 +4873,22 @@ phrase ``it is an error if'' to indicate a situation which is not
4875supposed to arise in complying programs; implementations are strongly 4873supposed to arise in complying programs; implementations are strongly
4876encouraged but not required to signal an error in these situations. 4874encouraged but not required to signal an error in these situations.
4877This package sometimes omits such error checking in the interest of 4875This package sometimes omits such error checking in the interest of
4878compactness and efficiency. For example, @code{do} variable 4876compactness and efficiency. For example, @code{cl-do} variable
4879specifiers are supposed to be lists of one, two, or three forms; 4877specifiers are supposed to be lists of one, two, or three forms;
4880extra forms are ignored by this package rather than signaling a 4878extra forms are ignored by this package rather than signaling a
4881syntax error. The @code{endp} function is simply a synonym for 4879syntax error. The @code{cl-endp} function is simply a synonym for
4882@code{null} in this package. Functions taking keyword arguments 4880@code{null} in this package. Functions taking keyword arguments
4883will accept an odd number of arguments, treating the trailing 4881will accept an odd number of arguments, treating the trailing
4884keyword as if it were followed by the value @code{nil}. 4882keyword as if it were followed by the value @code{nil}.
4885 4883
4886Argument lists (as processed by @code{defun*} and friends) 4884Argument lists (as processed by @code{cl-defun} and friends)
4887@emph{are} checked rigorously except for the minor point just 4885@emph{are} checked rigorously except for the minor point just
4888mentioned; in particular, keyword arguments are checked for 4886mentioned; in particular, keyword arguments are checked for
4889validity, and @code{&allow-other-keys} and @code{:allow-other-keys} 4887validity, and @code{&allow-other-keys} and @code{:allow-other-keys}
4890are fully implemented. Keyword validity checking is slightly 4888are fully implemented. Keyword validity checking is slightly
4891time consuming (though not too bad in byte-compiled code); 4889time consuming (though not too bad in byte-compiled code);
4892you can use @code{&allow-other-keys} to omit this check. Functions 4890you can use @code{&allow-other-keys} to omit this check. Functions
4893defined in this package such as @code{find} and @code{member*} 4891defined in this package such as @code{cl-find} and @code{cl-member}
4894do check their keyword arguments for validity. 4892do check their keyword arguments for validity.
4895 4893
4896@ifinfo 4894@ifinfo
@@ -4904,10 +4902,10 @@ do check their keyword arguments for validity.
4904Use of the optimizing Emacs compiler is highly recommended; many of the Common 4902Use of the optimizing Emacs compiler is highly recommended; many of the Common
4905Lisp macros emit 4903Lisp macros emit
4906code which can be improved by optimization. In particular, 4904code which can be improved by optimization. In particular,
4907@code{block}s (whether explicit or implicit in constructs like 4905@code{cl-block}s (whether explicit or implicit in constructs like
4908@code{defun*} and @code{loop}) carry a fair run-time penalty; the 4906@code{cl-defun} and @code{cl-loop}) carry a fair run-time penalty; the
4909optimizing compiler removes @code{block}s which are not actually 4907optimizing compiler removes @code{cl-block}s which are not actually
4910referenced by @code{return} or @code{return-from} inside the block. 4908referenced by @code{cl-return} or @code{cl-return-from} inside the block.
4911 4909
4912@node Common Lisp Compatibility 4910@node Common Lisp Compatibility
4913@appendix Common Lisp Compatibility 4911@appendix Common Lisp Compatibility
@@ -4916,20 +4914,22 @@ referenced by @code{return} or @code{return-from} inside the block.
4916Following is a list of all known incompatibilities between this 4914Following is a list of all known incompatibilities between this
4917package and Common Lisp as documented in Steele (2nd edition). 4915package and Common Lisp as documented in Steele (2nd edition).
4918 4916
4917@ignore
4919Certain function names, such as @code{member}, @code{assoc}, and 4918Certain function names, such as @code{member}, @code{assoc}, and
4920@code{floor}, were already taken by (incompatible) Emacs Lisp 4919@code{floor}, were already taken by (incompatible) Emacs Lisp
4921functions; this package appends @samp{*} to the names of its 4920functions; this package appends @samp{*} to the names of its
4922Common Lisp versions of these functions. 4921Common Lisp versions of these functions.
4922@end ignore
4923 4923
4924The word @code{defun*} is required instead of @code{defun} in order 4924The word @code{cl-defun} is required instead of @code{defun} in order
4925to use extended Common Lisp argument lists in a function. Likewise, 4925to use extended Common Lisp argument lists in a function. Likewise,
4926@code{defmacro*} and @code{function*} are versions of those forms 4926@code{cl-defmacro} and @code{cl-function} are versions of those forms
4927which understand full-featured argument lists. The @code{&whole} 4927which understand full-featured argument lists. The @code{&whole}
4928keyword does not work in @code{defmacro} argument lists (except 4928keyword does not work in @code{defmacro} argument lists (except
4929inside recursive argument lists). 4929inside recursive argument lists).
4930 4930
4931The @code{equal} predicate does not distinguish 4931The @code{equal} predicate does not distinguish
4932between IEEE floating-point plus and minus zero. The @code{equalp} 4932between IEEE floating-point plus and minus zero. The @code{cl-equalp}
4933predicate has several differences with Common Lisp; @pxref{Predicates}. 4933predicate has several differences with Common Lisp; @pxref{Predicates}.
4934 4934
4935The @code{setf} mechanism is entirely compatible, except that 4935The @code{setf} mechanism is entirely compatible, except that
@@ -4937,21 +4937,21 @@ setf-methods return a list of five values rather than five
4937values directly. Also, the new ``@code{setf} function'' concept 4937values directly. Also, the new ``@code{setf} function'' concept
4938(typified by @code{(defun (setf foo) @dots{})}) is not implemented. 4938(typified by @code{(defun (setf foo) @dots{})}) is not implemented.
4939 4939
4940The @code{do-all-symbols} form is the same as @code{do-symbols} 4940The @code{cl-do-all-symbols} form is the same as @code{cl-do-symbols}
4941with no @var{obarray} argument. In Common Lisp, this form would 4941with no @var{obarray} argument. In Common Lisp, this form would
4942iterate over all symbols in all packages. Since Emacs obarrays 4942iterate over all symbols in all packages. Since Emacs obarrays
4943are not a first-class package mechanism, there is no way for 4943are not a first-class package mechanism, there is no way for
4944@code{do-all-symbols} to locate any but the default obarray. 4944@code{cl-do-all-symbols} to locate any but the default obarray.
4945 4945
4946The @code{loop} macro is complete except that @code{loop-finish} 4946The @code{cl-loop} macro is complete except that @code{loop-finish}
4947and type specifiers are unimplemented. 4947and type specifiers are unimplemented.
4948 4948
4949The multiple-value return facility treats lists as multiple 4949The multiple-value return facility treats lists as multiple
4950values, since Emacs Lisp cannot support multiple return values 4950values, since Emacs Lisp cannot support multiple return values
4951directly. The macros will be compatible with Common Lisp if 4951directly. The macros will be compatible with Common Lisp if
4952@code{values} or @code{values-list} is always used to return to 4952@code{values} or @code{values-list} is always used to return to
4953a @code{multiple-value-bind} or other multiple-value receiver; 4953a @code{cl-multiple-value-bind} or other multiple-value receiver;
4954if @code{values} is used without @code{multiple-value-@dots{}} 4954if @code{values} is used without @code{cl-multiple-value-@dots{}}
4955or vice-versa the effect will be different from Common Lisp. 4955or vice-versa the effect will be different from Common Lisp.
4956 4956
4957Many Common Lisp declarations are ignored, and others match 4957Many Common Lisp declarations are ignored, and others match
@@ -4960,17 +4960,18 @@ example, local @code{special} declarations, which are purely
4960advisory in Emacs Lisp, do not rigorously obey the scoping rules 4960advisory in Emacs Lisp, do not rigorously obey the scoping rules
4961set down in Steele's book. 4961set down in Steele's book.
4962 4962
4963The variable @code{*gensym-counter*} starts out with a pseudo-random 4963The variable @code{cl--gensym-counter} starts out with a pseudo-random
4964value rather than with zero. This is to cope with the fact that 4964value rather than with zero. This is to cope with the fact that
4965generated symbols become interned when they are written to and 4965generated symbols become interned when they are written to and
4966loaded back from a file. 4966loaded back from a file.
4967 4967
4968The @code{defstruct} facility is compatible, except that structures 4968The @code{cl-defstruct} facility is compatible, except that structures
4969are of type @code{:type vector :named} by default rather than some 4969are of type @code{:type vector :named} by default rather than some
4970special, distinct type. Also, the @code{:type} slot option is ignored. 4970special, distinct type. Also, the @code{:type} slot option is ignored.
4971 4971
4972The second argument of @code{check-type} is treated differently. 4972The second argument of @code{cl-check-type} is treated differently.
4973 4973
4974@c FIXME Time to remove this?
4974@node Old CL Compatibility 4975@node Old CL Compatibility
4975@appendix Old CL Compatibility 4976@appendix Old CL Compatibility
4976 4977
@@ -4989,6 +4990,7 @@ is more predictable though more noticeably different from Common Lisp.
4989The @code{defkeyword} form and @code{keywordp} function are not 4990The @code{defkeyword} form and @code{keywordp} function are not
4990implemented in this package. 4991implemented in this package.
4991 4992
4993@ignore
4992The @code{member}, @code{floor}, @code{ceiling}, @code{truncate}, 4994The @code{member}, @code{floor}, @code{ceiling}, @code{truncate},
4993@code{round}, @code{mod}, and @code{rem} functions are suffixed 4995@code{round}, @code{mod}, and @code{rem} functions are suffixed
4994by @samp{*} in this package to avoid collision with existing 4996by @samp{*} in this package to avoid collision with existing
@@ -4998,6 +5000,7 @@ causing serious portability problems. (Some more
4998recent versions of the Quiroz package changed the names to 5000recent versions of the Quiroz package changed the names to
4999@code{cl-member}, etc.; this package defines the latter names as 5001@code{cl-member}, etc.; this package defines the latter names as
5000aliases for @code{member*}, etc.) 5002aliases for @code{member*}, etc.)
5003@end ignore
5001 5004
5002Certain functions in the old package which were buggy or inconsistent 5005Certain functions in the old package which were buggy or inconsistent
5003with the Common Lisp standard are incompatible with the conforming 5006with the Common Lisp standard are incompatible with the conforming
@@ -5006,9 +5009,9 @@ were synonyms for @code{eq} and @code{memq} in that package, @code{setf}
5006failed to preserve correct order of evaluation of its arguments, etc. 5009failed to preserve correct order of evaluation of its arguments, etc.
5007 5010
5008Finally, unlike the older package, this package is careful to 5011Finally, unlike the older package, this package is careful to
5009prefix all of its internal names with @code{cl-}. Except for a 5012prefix all of its internal names with @code{cl--}. Except for a
5010few functions which are explicitly defined as additional features 5013few functions which are explicitly defined as additional features
5011(such as @code{floatp-safe} and @code{letf}), this package does not 5014(such as @code{cl-floatp-safe} and @code{letf}), this package does not
5012export any non-@samp{cl-} symbols which are not also part of Common 5015export any non-@samp{cl-} symbols which are not also part of Common
5013Lisp. 5016Lisp.
5014 5017
@@ -5267,7 +5270,7 @@ where a more iteratively-minded programmer might write one of
5267these forms: 5270these forms:
5268 5271
5269@example 5272@example
5270(let ((total 0)) (dolist (x my-list) (incf total x)) total) 5273(let ((total 0)) (dolist (x my-list) (cl-incf total x)) total)
5271(loop for x in my-list sum x) 5274(loop for x in my-list sum x)
5272@end example 5275@end example
5273 5276