diff options
| author | Glenn Morris | 2012-10-24 00:41:11 -0700 |
|---|---|---|
| committer | Glenn Morris | 2012-10-24 00:41:11 -0700 |
| commit | 39a58b5b51a881b4960600814653c3efd8e1ffb9 (patch) | |
| tree | 53feccf0a34e74a4ce4dfe9dc0cb62277923314f | |
| parent | 72ec96fb41e2e53ac5fda7532b0d3753e5ff971e (diff) | |
| download | emacs-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/ChangeLog | 8 | ||||
| -rw-r--r-- | doc/misc/cl.texi | 1131 |
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 @@ | |||
| 1 | 2012-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 | |||
| 1 | 2012-10-24 Paul Eggert <eggert@penguin.cs.ucla.edu> | 9 | 2012-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 | |||
| 1047 | the proper left-to-right order; for example, | 1047 | the 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 |
| 1054 | looks like it will evaluate @code{(incf i)} exactly once, before the | 1054 | looks like it will evaluate @code{(cl-incf i)} exactly once, before the |
| 1055 | following access to @code{i}; the @code{setf} expander will insert | 1055 | following access to @code{i}; the @code{setf} expander will insert |
| 1056 | temporary variables as necessary to ensure that it does in fact work | 1056 | temporary variables as necessary to ensure that it does in fact work |
| 1057 | this way no matter what setf-method is defined for @code{aref}. | 1057 | this 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} | |||
| 1081 | that operate on generalized variables. Many are interesting and | 1081 | that operate on generalized variables. Many are interesting and |
| 1082 | useful even when the @var{place} is just a variable name. | 1082 | useful 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{} |
| 1085 | This macro is to @code{setf} what @code{cl-psetq} is to @code{setq}: | 1085 | This macro is to @code{setf} what @code{cl-psetq} is to @code{setq}: |
| 1086 | When several @var{place}s and @var{form}s are involved, the | 1086 | When several @var{place}s and @var{form}s are involved, the |
| 1087 | assignments take place in parallel rather than sequentially. | 1087 | assignments take place in parallel rather than sequentially. |
| @@ -1089,17 +1089,17 @@ Specifically, all subforms are evaluated from left to right, then | |||
| 1089 | all the assignments are done (in an undefined order). | 1089 | all 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 |
| 1093 | This macro increments the number stored in @var{place} by one, or | 1093 | This macro increments the number stored in @var{place} by one, or |
| 1094 | by @var{x} if specified. The incremented value is returned. For | 1094 | by @var{x} if specified. The incremented value is returned. For |
| 1095 | example, @code{(incf i)} is equivalent to @code{(setq i (1+ i))}, and | 1095 | example, @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 | ||
| 1098 | Once again, care is taken to preserve the ``apparent'' order of | 1098 | Once again, care is taken to preserve the ``apparent'' order of |
| 1099 | evaluation. For example, | 1099 | evaluation. 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 |
| 1116 | but rather to something more like | 1116 | but 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 |
| 1124 | Again, all of this is taken care of automatically by @code{incf} and | 1124 | Again, all of this is taken care of automatically by @code{cl-incf} and |
| 1125 | the other generalized-variable macros. | 1125 | the other generalized-variable macros. |
| 1126 | 1126 | ||
| 1127 | As a more Emacs-specific example of @code{incf}, the expression | 1127 | As 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 |
| 1133 | This macro decrements the number stored in @var{place} by one, or | 1133 | This macro decrements the number stored in @var{place} by one, or |
| 1134 | by @var{x} if specified. | 1134 | by @var{x} if specified. |
| 1135 | @end defspec | 1135 | @end defspec |
| @@ -1256,7 +1256,7 @@ It does the bindings in sequential rather than parallel order. | |||
| 1256 | This is the ``generic'' modify macro. It calls @var{function}, | 1256 | This is the ``generic'' modify macro. It calls @var{function}, |
| 1257 | which should be an unquoted function name, macro name, or lambda. | 1257 | which should be an unquoted function name, macro name, or lambda. |
| 1258 | It passes @var{place} and @var{args} as arguments, and assigns the | 1258 | It passes @var{place} and @var{args} as arguments, and assigns the |
| 1259 | result back to @var{place}. For example, @code{(incf @var{place} | 1259 | result 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})}. |
| 1261 | Some more examples: | 1261 | Some 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 | ||
| 1281 | The @code{callf} and @code{callf2} macros serve as building | 1281 | The @code{callf} and @code{callf2} macros serve as building |
| 1282 | blocks for other macros like @code{incf}, @code{pushnew}, and | 1282 | blocks 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*} |
| 1284 | macros are used in the processing of symbol macros; | 1284 | macros 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] |
| 1296 | This macro defines a ``read-modify-write'' macro similar to | 1296 | This 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 |
| 1298 | to take a @var{place} argument followed by additional arguments | 1298 | to take a @var{place} argument followed by additional arguments |
| 1299 | described by @var{arglist}. The call | 1299 | described by @var{arglist}. The call |
| 1300 | 1300 | ||
| @@ -1306,7 +1306,7 @@ described by @var{arglist}. The call | |||
| 1306 | will be expanded to | 1306 | will 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 | |||
| 1319 | For example: | 1319 | For 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 | ||
| 1326 | Note that @code{&key} is not allowed in @var{arglist}, but | 1326 | Note 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 | ||
| 1400 | The Lisp form that is returned can access the arguments from | 1400 | The 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; |
| 1402 | macros like @code{setf} and @code{incf} which invoke this | 1402 | macros like @code{setf} and @code{cl-incf} which invoke this |
| 1403 | setf-method will insert temporary variables as needed to make | 1403 | setf-method will insert temporary variables as needed to make |
| 1404 | sure the apparent order of evaluation is preserved. | 1404 | sure 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 |
| 1453 | arguments in the place form, and the first return value is a | 1453 | arguments in the place form, and the first return value is a |
| 1454 | list of a corresponding number of temporary variables generated | 1454 | list of a corresponding number of temporary variables generated |
| 1455 | by @code{gensym}. Macros like @code{setf} and @code{incf} which | 1455 | by @code{cl-gensym}. Macros like @code{setf} and @code{cl-incf} which |
| 1456 | use this setf-method will optimize away most temporaries that | 1456 | use this setf-method will optimize away most temporaries that |
| 1457 | turn out to be unnecessary, so there is little reason for the | 1457 | turn out to be unnecessary, so there is little reason for the |
| 1458 | setf-method itself to optimize. | 1458 | setf-method itself to optimize. |
| @@ -1463,11 +1463,12 @@ This function returns the setf-method for @var{place}, by | |||
| 1463 | invoking the definition previously recorded by @code{defsetf} | 1463 | invoking the definition previously recorded by @code{defsetf} |
| 1464 | or @code{define-setf-method}. The result is a list of five | 1464 | or @code{define-setf-method}. The result is a list of five |
| 1465 | values as described above. You can use this function to build | 1465 | values as described above. You can use this function to build |
| 1466 | your own @code{incf}-like modify macros. (Actually, it is | 1466 | your own @code{cl-incf}-like modify macros. (Actually, it is |
| 1467 | @c FIXME? | ||
| 1467 | better to use the internal functions @code{cl-setf-do-modify} | 1468 | better to use the internal functions @code{cl-setf-do-modify} |
| 1468 | and @code{cl-setf-do-store}, which are a bit easier to use and | 1469 | and @code{cl-setf-do-store}, which are a bit easier to use and |
| 1469 | which also do a number of optimizations; consult the source | 1470 | which also do a number of optimizations; consult the source |
| 1470 | code for the @code{incf} function for a simple example.) | 1471 | code for the @code{cl-incf} function for a simple example.) |
| 1471 | 1472 | ||
| 1472 | The argument @var{env} specifies the ``environment'' to be | 1473 | The argument @var{env} specifies the ``environment'' to be |
| 1473 | passed on to @code{macroexpand} if @code{get-setf-method} should | 1474 | passed on to @code{macroexpand} if @code{get-setf-method} should |
| @@ -1504,14 +1505,14 @@ defined later. | |||
| 1504 | These Lisp forms make bindings to variables and function names, | 1505 | These Lisp forms make bindings to variables and function names, |
| 1505 | analogous to Lisp's built-in @code{let} form. | 1506 | analogous 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 |
| 1508 | are also related to variable bindings. | 1509 | are 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 |
| 1521 | The standard @code{let} form binds variables whose names are known | 1522 | The standard @code{let} form binds variables whose names are known |
| 1522 | at compile-time. The @code{progv} form provides an easy way to | 1523 | at compile-time. The @code{cl-progv} form provides an easy way to |
| 1523 | bind variables whose names are computed at run-time. | 1524 | bind 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{} |
| 1526 | This form establishes @code{let}-style variable bindings on a | 1527 | This form establishes @code{let}-style variable bindings on a |
| 1527 | set of variables computed at run-time. The expressions | 1528 | set 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 | |||
| 1696 | fail if byte-compiled. In such cases, use @code{labels} instead. | 1697 | fail if byte-compiled. In such cases, use @code{labels} instead. |
| 1697 | 1698 | ||
| 1698 | Functions defined by @code{flet} may use the full Common Lisp | 1699 | Functions defined by @code{flet} may use the full Common Lisp |
| 1699 | argument notation supported by @code{defun*}; also, the function | 1700 | argument notation supported by @code{cl-defun}; also, the function |
| 1700 | body is enclosed in an implicit block as if by @code{defun*}. | 1701 | body 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 |
| 1731 | These forms create local macros and ``symbol macros.'' | 1732 | These forms create local macros and ``symbol macros.'' |
| 1732 | 1733 | ||
| 1733 | @defspec macrolet (bindings@dots{}) forms@dots{} | 1734 | @defspec cl-macrolet (bindings@dots{}) forms@dots{} |
| 1734 | This form is analogous to @code{flet}, but for macros instead of | 1735 | This form is analogous to @code{flet}, but for macros instead of |
| 1735 | functions. Each @var{binding} is a list of the same form as the | 1736 | functions. Each @var{binding} is a list of the same form as the |
| 1736 | arguments to @code{defmacro*} (i.e., a macro name, argument list, | 1737 | arguments to @code{cl-defmacro} (i.e., a macro name, argument list, |
| 1737 | and macro-expander forms). The macro is defined accordingly for | 1738 | and macro-expander forms). The macro is defined accordingly for |
| 1738 | use within the body of the @code{macrolet}. | 1739 | use within the body of the @code{cl-macrolet}. |
| 1739 | 1740 | ||
| 1740 | Because of the nature of macros, @code{macrolet} is lexically | 1741 | Because of the nature of macros, @code{cl-macrolet} is lexically |
| 1741 | scoped even in Emacs Lisp: The @code{macrolet} binding will | 1742 | scoped even in Emacs Lisp: The @code{cl-macrolet} binding will |
| 1742 | affect only calls that appear physically within the body | 1743 | affect 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 |
| 1744 | body. | 1745 | body. |
| 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{} |
| 1748 | This form creates @dfn{symbol macros}, which are macros that look | 1749 | This form creates @dfn{symbol macros}, which are macros that look |
| 1749 | like variable references rather than function calls. Each | 1750 | like 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)) |
| 1758 | bar | 1759 | bar |
| 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 | |||
| 1766 | Likewise, a @code{let} or @code{let*} binding a symbol macro is | 1767 | Likewise, a @code{let} or @code{let*} binding a symbol macro is |
| 1767 | treated like a @code{letf} or @code{letf*}. This differs from true | 1768 | treated like a @code{letf} or @code{letf*}. This differs from true |
| 1768 | Common Lisp, where the rules of lexical scoping cause a @code{let} | 1769 | Common Lisp, where the rules of lexical scoping cause a @code{let} |
| 1769 | binding to shadow a @code{symbol-macrolet} binding. In this package, | 1770 | binding to shadow a @code{cl-symbol-macrolet} binding. In this package, |
| 1770 | only @code{lexical-let} and @code{lexical-let*} will shadow a symbol | 1771 | only @code{lexical-let} and @code{lexical-let*} will shadow a symbol |
| 1771 | macro. | 1772 | macro. |
| 1772 | 1773 | ||
| 1773 | There is no analogue of @code{defmacro} for symbol macros; all symbol | 1774 | There is no analogue of @code{defmacro} for symbol macros; all symbol |
| 1774 | macros are local. A typical use of @code{symbol-macrolet} is in the | 1775 | macros are local. A typical use of @code{cl-symbol-macrolet} is in the |
| 1775 | expansion of another macro: | 1776 | expansion 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)) |
| 1786 | mylist | 1787 | mylist |
| 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 | |||
| 1794 | shown here expands to | 1795 | shown 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 |
| 1803 | which in turn expands to | 1804 | which 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. |
| 1810 | This package defines a nonstandard @code{in-ref} loop clause that | 1811 | This package defines a nonstandard @code{in-ref} loop clause that |
| 1811 | works much like @code{my-dolist}. | 1812 | works much like @code{my-dolist}. |
| 1812 | @end defspec | 1813 | @end defspec |
| @@ -1818,11 +1819,11 @@ works much like @code{my-dolist}. | |||
| 1818 | These conditional forms augment Emacs Lisp's simple @code{if}, | 1819 | These 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{} |
| 1822 | This macro evaluates @var{keyform}, then compares it with the key | 1823 | This macro evaluates @var{keyform}, then compares it with the key |
| 1823 | values listed in the various @var{clause}s. Whichever clause matches | 1824 | values listed in the various @var{clause}s. Whichever clause matches |
| 1824 | the key is executed; comparison is done by @code{eql}. If no clause | 1825 | the key is executed; comparison is done by @code{eql}. If no clause |
| 1825 | matches, the @code{case} form returns @code{nil}. The clauses are | 1826 | matches, the @code{cl-case} form returns @code{nil}. The clauses are |
| 1826 | of the form | 1827 | of 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}, | |||
| 1846 | a @key{RET} or @kbd{C-j}, or anything else. | 1847 | a @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{} |
| 1858 | This macro is just like @code{case}, except that if the key does | 1859 | This macro is just like @code{cl-case}, except that if the key does |
| 1859 | not match any of the clauses, an error is signaled rather than | 1860 | not match any of the clauses, an error is signaled rather than |
| 1860 | simply returning @code{nil}. | 1861 | simply returning @code{nil}. |
| 1861 | @end defspec | 1862 | @end defspec |
| 1862 | 1863 | ||
| 1863 | @defspec typecase keyform clause@dots{} | 1864 | @defspec cl-typecase keyform clause@dots{} |
| 1864 | This macro is a version of @code{case} that checks for types | 1865 | This macro is a version of @code{cl-case} that checks for types |
| 1865 | rather than values. Each @var{clause} is of the form | 1866 | rather 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}, |
| 1867 | for a description of type specifiers. For example, | 1868 | for 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 | |||
| 1879 | several types, use an @code{(or ...)} type specifier. | 1880 | several 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{} |
| 1883 | This macro is just like @code{typecase}, except that if the key does | 1884 | This macro is just like @code{cl-typecase}, except that if the key does |
| 1884 | not match any of the clauses, an error is signaled rather than | 1885 | not match any of the clauses, an error is signaled rather than |
| 1885 | simply returning @code{nil}. | 1886 | simply returning @code{nil}. |
| 1886 | @end defspec | 1887 | @end defspec |
| @@ -1891,26 +1892,26 @@ simply returning @code{nil}. | |||
| 1891 | @noindent | 1892 | @noindent |
| 1892 | Common Lisp @dfn{blocks} provide a non-local exit mechanism very | 1893 | Common Lisp @dfn{blocks} provide a non-local exit mechanism very |
| 1893 | similar to @code{catch} and @code{throw}, but lexically rather than | 1894 | similar to @code{catch} and @code{throw}, but lexically rather than |
| 1894 | dynamically scoped. This package actually implements @code{block} | 1895 | dynamically scoped. This package actually implements @code{cl-block} |
| 1895 | in terms of @code{catch}; however, the lexical scoping allows the | 1896 | in terms of @code{catch}; however, the lexical scoping allows the |
| 1896 | optimizing byte-compiler to omit the costly @code{catch} step if the | 1897 | optimizing byte-compiler to omit the costly @code{catch} step if the |
| 1897 | body of the block does not actually @code{return-from} the block. | 1898 | body 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{} |
| 1900 | The @var{forms} are evaluated as if by a @code{progn}. However, | 1901 | The @var{forms} are evaluated as if by a @code{progn}. However, |
| 1901 | if any of the @var{forms} execute @code{(return-from @var{name})}, | 1902 | if any of the @var{forms} execute @code{(cl-return-from @var{name})}, |
| 1902 | they will jump out and return directly from the @code{block} form. | 1903 | they will jump out and return directly from the @code{cl-block} form. |
| 1903 | The @code{block} returns the result of the last @var{form} unless | 1904 | The @code{cl-block} returns the result of the last @var{form} unless |
| 1904 | a @code{return-from} occurs. | 1905 | a @code{cl-return-from} occurs. |
| 1905 | 1906 | ||
| 1906 | The @code{block}/@code{return-from} mechanism is quite similar to | 1907 | The @code{cl-block}/@code{cl-return-from} mechanism is quite similar to |
| 1907 | the @code{catch}/@code{throw} mechanism. The main differences are | 1908 | the @code{catch}/@code{throw} mechanism. The main differences are |
| 1908 | that block @var{name}s are unevaluated symbols, rather than forms | 1909 | that 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 |
| 1910 | also that blocks are lexically scoped whereas @code{catch}/@code{throw} | 1911 | also that blocks are lexically scoped whereas @code{catch}/@code{throw} |
| 1911 | are dynamically scoped. This means that functions called from the | 1912 | are dynamically scoped. This means that functions called from the |
| 1912 | body of a @code{catch} can also @code{throw} to the @code{catch}, | 1913 | body of a @code{catch} can also @code{throw} to the @code{catch}, |
| 1913 | but the @code{return-from} referring to a block name must appear | 1914 | but the @code{cl-return-from} referring to a block name must appear |
| 1914 | physically within the @var{forms} that make up the body of the block. | 1915 | physically within the @var{forms} that make up the body of the block. |
| 1915 | They may not appear within other called functions, although they may | 1916 | They may not appear within other called functions, although they may |
| 1916 | appear within macro expansions or @code{lambda}s in the body. Block | 1917 | appear within macro expansions or @code{lambda}s in the body. Block |
| @@ -1919,11 +1920,11 @@ names and @code{catch} names form independent name-spaces. | |||
| 1919 | In true Common Lisp, @code{defun} and @code{defmacro} surround | 1920 | In true Common Lisp, @code{defun} and @code{defmacro} surround |
| 1920 | the function or expander bodies with implicit blocks with the | 1921 | the function or expander bodies with implicit blocks with the |
| 1921 | same name as the function or macro. This does not occur in Emacs | 1922 | same name as the function or macro. This does not occur in Emacs |
| 1922 | Lisp, but this package provides @code{defun*} and @code{defmacro*} | 1923 | Lisp, but this package provides @code{cl-defun} and @code{cl-defmacro} |
| 1923 | forms which do create the implicit block. | 1924 | forms which do create the implicit block. |
| 1924 | 1925 | ||
| 1925 | The Common Lisp looping constructs defined by this package, | 1926 | The Common Lisp looping constructs defined by this package, |
| 1926 | such as @code{loop} and @code{dolist}, also create implicit blocks | 1927 | such as @code{cl-loop} and @code{cl-dolist}, also create implicit blocks |
| 1927 | just as in Common Lisp. | 1928 | just as in Common Lisp. |
| 1928 | 1929 | ||
| 1929 | Because they are implemented in terms of Emacs Lisp @code{catch} | 1930 | Because 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, |
| 1932 | the optimizing byte compiler will optimize away the @code{catch} | 1933 | the optimizing byte compiler will optimize away the @code{catch} |
| 1933 | if the block does | 1934 | if the block does |
| 1934 | not in fact contain any @code{return} or @code{return-from} calls | 1935 | not in fact contain any @code{cl-return} or @code{cl-return-from} calls |
| 1935 | that jump to it. This means that @code{do} loops and @code{defun*} | 1936 | that jump to it. This means that @code{cl-do} loops and @code{cl-defun} |
| 1936 | functions which don't use @code{return} don't pay the overhead to | 1937 | functions which don't use @code{cl-return} don't pay the overhead to |
| 1937 | support it. | 1938 | support it. |
| 1938 | @end defspec | 1939 | @end defspec |
| 1939 | 1940 | ||
| 1940 | @defspec return-from name [result] | 1941 | @defspec cl-return-from name [result] |
| 1941 | This macro returns from the block named @var{name}, which must be | 1942 | This macro returns from the block named @var{name}, which must be |
| 1942 | an (unevaluated) symbol. If a @var{result} form is specified, it | 1943 | an (unevaluated) symbol. If a @var{result} form is specified, it |
| 1943 | is evaluated to produce the result returned from the @code{block}. | 1944 | is evaluated to produce the result returned from the @code{block}. |
| 1944 | Otherwise, @code{nil} is returned. | 1945 | Otherwise, @code{nil} is returned. |
| 1945 | @end defspec | 1946 | @end defspec |
| 1946 | 1947 | ||
| 1947 | @defspec return [result] | 1948 | @defspec cl-return [result] |
| 1948 | This macro is exactly like @code{(return-from nil @var{result})}. | 1949 | This macro is exactly like @code{(cl-return-from nil @var{result})}. |
| 1949 | Common Lisp loops like @code{do} and @code{dolist} implicitly enclose | 1950 | Common Lisp loops like @code{cl-do} and @code{cl-dolist} implicitly enclose |
| 1950 | themselves in @code{nil} blocks. | 1951 | themselves 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 | |||
| 1958 | looping constructs to complement Emacs Lisp's basic @code{while} | 1959 | looping constructs to complement Emacs Lisp's basic @code{while} |
| 1959 | loop. | 1960 | loop. |
| 1960 | 1961 | ||
| 1961 | @defspec loop forms@dots{} | 1962 | @defspec cl-loop forms@dots{} |
| 1962 | The @code{CL} package supports both the simple, old-style meaning of | 1963 | The @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 |
| 1964 | the @dfn{Loop Facility} or @dfn{Loop Macro}. This more advanced | 1965 | the @dfn{Loop Facility} or @dfn{Loop Macro}. This more advanced |
| 1965 | facility is discussed in the following section; @pxref{Loop Facility}. | 1966 | facility is discussed in the following section; @pxref{Loop Facility}. |
| 1966 | The simple form of @code{loop} is described here. | 1967 | The simple form of @code{loop} is described here. |
| 1967 | 1968 | ||
| 1968 | If @code{loop} is followed by zero or more Lisp expressions, | 1969 | If @code{cl-loop} is followed by zero or more Lisp expressions, |
| 1969 | then @code{(loop @var{exprs}@dots{})} simply creates an infinite | 1970 | then @code{(cl-loop @var{exprs}@dots{})} simply creates an infinite |
| 1970 | loop executing the expressions over and over. The loop is | 1971 | loop executing the expressions over and over. The loop is |
| 1971 | enclosed in an implicit @code{nil} block. Thus, | 1972 | enclosed 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 |
| 1978 | is exactly equivalent to | 1979 | is 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 | ||
| 1984 | If any of the expressions are plain symbols, the loop is instead | 1985 | If 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 | |||
| 1988 | value of a variable.) | 1989 | value 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{} |
| 1992 | This macro creates a general iterative loop. Each @var{spec} is | 1993 | This macro creates a general iterative loop. Each @var{spec} is |
| 1993 | of the form | 1994 | of the form |
| 1994 | 1995 | ||
| @@ -2006,8 +2007,8 @@ begins. Once the @var{end-test} becomes true, the @var{result} | |||
| 2006 | forms are evaluated (with the @var{var}s still bound to their | 2007 | forms are evaluated (with the @var{var}s still bound to their |
| 2007 | values) to produce the result returned by @code{do}. | 2008 | values) to produce the result returned by @code{do}. |
| 2008 | 2009 | ||
| 2009 | The entire @code{do} loop is enclosed in an implicit @code{nil} | 2010 | The entire @code{cl-do} loop is enclosed in an implicit @code{nil} |
| 2010 | block, so that you can use @code{(return)} to break out of the | 2011 | block, so that you can use @code{(cl-return)} to break out of the |
| 2011 | loop at any time. | 2012 | loop at any time. |
| 2012 | 2013 | ||
| 2013 | If there are no @var{result} forms, the loop returns @code{nil}. | 2014 | If 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 | |||
| 2023 | This example (from Steele) illustrates a loop which applies the | 2024 | This example (from Steele) illustrates a loop which applies the |
| 2024 | function @code{f} to successive pairs of values from the lists | 2025 | function @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 |
| 2028 | the rest of the loop. | 2029 | the 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{} |
| 2040 | This is to @code{do} what @code{let*} is to @code{let}. In | 2041 | This is to @code{cl-do} what @code{let*} is to @code{let}. In |
| 2041 | particular, the initial values are bound as if by @code{let*} | 2042 | particular, the initial values are bound as if by @code{let*} |
| 2042 | rather than @code{let}, and the steps are assigned as if by | 2043 | rather 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 | |||
| 2045 | Here is another way to write the above loop: | 2046 | Here 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{} |
| 2060 | This is a more specialized loop which iterates across the elements | 2061 | This is a more specialized loop which iterates across the elements |
| 2061 | of a list. @var{list} should evaluate to a list; the body @var{forms} | 2062 | of a list. @var{list} should evaluate to a list; the body @var{forms} |
| 2062 | are executed with @var{var} bound to each element of the list in | 2063 | are 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 | |||
| 2066 | surrounded by an implicit @code{nil} block. | 2067 | surrounded 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{} |
| 2070 | This is a more specialized loop which iterates a specified number | 2071 | This is a more specialized loop which iterates a specified number |
| 2071 | of times. The body is executed with @var{var} bound to the integers | 2072 | of times. The body is executed with @var{var} bound to the integers |
| 2072 | from zero (inclusive) to @var{count} (exclusive), in turn. Then | 2073 | from 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{} |
| 2080 | This loop iterates over all interned symbols. If @var{obarray} | 2081 | This loop iterates over all interned symbols. If @var{obarray} |
| 2081 | is specified and is not @code{nil}, it loops over all symbols in | 2082 | is specified and is not @code{nil}, it loops over all symbols in |
| 2082 | that obarray. For each symbol, the body @var{forms} are evaluated | 2083 | that 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 | |||
| 2086 | value. The loop is surrounded by an implicit @code{nil} block. | 2087 | value. 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{} |
| 2090 | This is identical to @code{do-symbols} except that the @var{obarray} | 2091 | This is identical to @code{cl-do-symbols} except that the @var{obarray} |
| 2091 | argument is omitted; it always iterates over the default obarray. | 2092 | argument 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,'' | |||
| 2108 | with an easy-to-use but very powerful and expressive syntax. | 2109 | with 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 |
| 2123 | The @code{loop} macro essentially creates a mini-language within | 2124 | The @code{cl-loop} macro essentially creates a mini-language within |
| 2124 | Lisp that is specially tailored for describing loops. While this | 2125 | Lisp that is specially tailored for describing loops. While this |
| 2125 | language is a little strange-looking by the standards of regular Lisp, | 2126 | language is a little strange-looking by the standards of regular Lisp, |
| 2126 | it turns out to be very easy to learn and well-suited to its purpose. | 2127 | it turns out to be very easy to learn and well-suited to its purpose. |
| 2127 | 2128 | ||
| 2128 | Since @code{loop} is a macro, all parsing of the loop language | 2129 | Since @code{cl-loop} is a macro, all parsing of the loop language |
| 2129 | takes place at byte-compile time; compiled @code{loop}s are just | 2130 | takes place at byte-compile time; compiled @code{cl-loop}s are just |
| 2130 | as efficient as the equivalent @code{while} loops written longhand. | 2131 | as efficient as the equivalent @code{while} loops written longhand. |
| 2131 | 2132 | ||
| 2132 | @defspec loop clauses@dots{} | 2133 | @defspec cl-loop clauses@dots{} |
| 2133 | A loop construct consists of a series of @var{clause}s, each | 2134 | A loop construct consists of a series of @var{clause}s, each |
| 2134 | introduced by a symbol like @code{for} or @code{do}. Clauses | 2135 | introduced by a symbol like @code{for} or @code{do}. Clauses |
| 2135 | are simply strung together in the argument list of @code{loop}, | 2136 | are simply strung together in the argument list of @code{cl-loop}, |
| 2136 | with minimal extra parentheses. The various types of clauses | 2137 | with minimal extra parentheses. The various types of clauses |
| 2137 | specify initializations, such as the binding of temporary | 2138 | specify initializations, such as the binding of temporary |
| 2138 | variables, actions to be taken in the loop, stepping actions, | 2139 | variables, actions to be taken in the loop, stepping actions, |
| @@ -2142,9 +2143,9 @@ Common Lisp specifies a certain general order of clauses in a | |||
| 2142 | loop: | 2143 | loop: |
| 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 | ||
| 2150 | The @var{name-clause} optionally gives a name to the implicit | 2151 | The @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 |
| 2156 | as computing, collecting, and returning values. | 2157 | as computing, collecting, and returning values. |
| 2157 | 2158 | ||
| 2158 | The Emacs version of the @code{loop} macro is less restrictive about | 2159 | The Emacs version of the @code{cl-loop} macro is less restrictive about |
| 2159 | the order of clauses, but things will behave most predictably if | 2160 | the order of clauses, but things will behave most predictably if |
| 2160 | you put the variable-binding clauses @code{with}, @code{for}, and | 2161 | you 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 |
| 2182 | Before listing the full set of clauses that are allowed, let's | 2183 | Before listing the full set of clauses that are allowed, let's |
| 2183 | look at a few example loops just to get a feel for the @code{loop} | 2184 | look at a few example loops just to get a feel for the @code{cl-loop} |
| 2184 | language. | 2185 | language. |
| 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 |
| 2192 | This loop iterates over all Emacs buffers, using the list | 2193 | This loop iterates over all Emacs buffers, using the list |
| 2193 | returned by @code{buffer-list}. For each buffer @code{buf}, | 2194 | returned by @code{buffer-list}. For each buffer @code{buf}, |
| 2194 | it calls @code{buffer-file-name} and collects the results into | 2195 | it calls @code{buffer-file-name} and collects the results into |
| 2195 | a list, which is then returned from the @code{loop} construct. | 2196 | a list, which is then returned from the @code{cl-loop} construct. |
| 2196 | The result is a list of the file names of all the buffers in | 2197 | The result is a list of the file names of all the buffers in |
| 2197 | Emacs's memory. The words @code{for}, @code{in}, and @code{collect} | 2198 | Emacs's memory. The words @code{for}, @code{in}, and @code{collect} |
| 2198 | are reserved words in the @code{loop} language. | 2199 | are 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 | |||
| 2206 | current buffer. | 2207 | current 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, | |||
| 2215 | the loop exits immediately. | 2216 | the 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} | |||
| 2223 | is always called at least once. | 2224 | is 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 |
| 2247 | define loops all by themselves, it still creates a single loop | 2248 | define loops all by themselves, it still creates a single loop |
| 2248 | rather than some sort of triple-nested loop. You must explicitly | 2249 | rather than some sort of triple-nested loop. You must explicitly |
| 2249 | nest your @code{loop} constructs if you want nested loops. | 2250 | nest 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)) |
| 2276 | i | 2277 | i |
| 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 | |||
| 2302 | that they are exclusive rather than inclusive limits: | 2303 | that 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 | ||
| 2311 | The @code{by} value is always positive, even for downward-counting | 2312 | The @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 | |||
| 2320 | function taking one argument. For example: | 2321 | function 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} |
| 2330 | This clause iterates @var{var} over all the cons cells of @var{list}. | 2331 | This 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 | ||
| 2337 | With @code{by}, there is no real reason that the @code{on} expression | 2338 | With @code{by}, there is no real reason that the @code{on} expression |
| 2338 | must be a list. For example: | 2339 | must 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 | |||
| 2352 | rather than just a temporary variable. For example, | 2353 | rather 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}, | |||
| 2364 | which may be a vector or a string. | 2365 | which 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. | |||
| 2397 | As an example, | 2398 | As 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 | ||
| 2412 | Due to a minor implementation restriction, it will not work to have | 2413 | Due to a minor implementation restriction, it will not work to have |
| 2413 | more than one @code{for} clause iterating over symbols, hash tables, | 2414 | more than one @code{for} clause iterating over symbols, hash tables, |
| 2414 | keymaps, overlays, or intervals in a given @code{loop}. Fortunately, | 2415 | keymaps, overlays, or intervals in a given @code{cl-loop}. Fortunately, |
| 2415 | it would rarely if ever be useful to do so. It @emph{is} valid to mix | 2416 | it would rarely if ever be useful to do so. It @emph{is} valid to mix |
| 2416 | one of these types of clauses with other clauses like @code{for ... to} | 2417 | one of these types of clauses with other clauses like @code{for ... to} |
| 2417 | or @code{while}. | 2418 | or @code{while}. |
| @@ -2423,10 +2424,10 @@ This clause iterates over the entries in @var{hash-table} with | |||
| 2423 | a second variable to the opposite part. | 2424 | a 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 | |||
| 2438 | together. | 2439 | together. |
| 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} | |||
| 2497 | these two loops are effectively the same: | 2498 | these 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 | ||
| 2504 | Note that this type of @code{for} clause does not imply any sort | 2505 | Note 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 | |||
| 2509 | the initial setting and for successive settings: | 2510 | the 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} | |||
| 2524 | and @code{cl-psetq}). | 2525 | and @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, | |||
| 2537 | based on the value of @code{x} left over from the previous time | 2538 | based on the value of @code{x} left over from the previous time |
| 2538 | through the loop. | 2539 | through the loop. |
| 2539 | 2540 | ||
| 2540 | Another feature of the @code{loop} macro is @dfn{destructuring}, | 2541 | Another feature of the @code{cl-loop} macro is @dfn{destructuring}, |
| 2541 | similar in concept to the destructuring provided by @code{defmacro}. | 2542 | similar in concept to the destructuring provided by @code{defmacro}. |
| 2542 | The @var{var} part of any @code{for} clause can be given as a list | 2543 | The @var{var} part of any @code{for} clause can be given as a list |
| 2543 | of variables instead of a single variable. The values produced | 2544 | of 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 | |||
| 2545 | stored in the corresponding variables. | 2546 | stored 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 | ||
| 2552 | In loop destructuring, if there are more values than variables | 2553 | In 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 | |||
| 2558 | to process an alist | 2559 | to 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 | |||
| 2577 | internal temporary variable. The loops | 2578 | internal 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 | |||
| 2607 | were non-@code{nil}, the loop returns @code{t}: | 2608 | were 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 | |||
| 2684 | accumulate into the same place. From Steele: | 2685 | accumulate 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 | |||
| 2704 | loops are basically equivalent: | 2705 | loops 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 | ||
| 2712 | Naturally, the variable @var{var} might be used for some purpose | 2713 | Naturally, the variable @var{var} might be used for some purpose |
| 2713 | in the rest of the loop. For example: | 2714 | in 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 | ||
| 2720 | This loop inserts the elements of @code{my-list} at the front of | 2721 | This 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 | ||
| 2766 | Note the use of @code{and} to put two clauses into the ``then'' | 2767 | Note 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 | |||
| 2828 | efficiently, though. | 2829 | efficiently, though. |
| 2829 | @end table | 2830 | @end table |
| 2830 | 2831 | ||
| 2831 | While there is no high-level way to add user extensions to @code{loop} | 2832 | While 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 |
| 2833 | does offer two properties called @code{cl-loop-handler} and | 2834 | does 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 |
| 2837 | file @file{cl-macs.el} for details. | 2838 | file @file{cl-macs.el} for details. |
| 2838 | 2839 | ||
| 2839 | This package's @code{loop} macro is compatible with that of Common | 2840 | This package's @code{cl-loop} macro is compatible with that of Common |
| 2840 | Lisp, except that a few features are not implemented: @code{loop-finish} | 2841 | Lisp, except that a few features are not implemented: @code{loop-finish} |
| 2841 | and data-type specifiers. Naturally, the @code{for} clauses which | 2842 | and data-type specifiers. Naturally, the @code{for} clauses which |
| 2842 | iterate over keymaps, overlays, intervals, frames, windows, and | 2843 | iterate over keymaps, overlays, intervals, frames, windows, and |
| @@ -2851,14 +2852,14 @@ functions, by contrast, always return exactly one result. This | |||
| 2851 | package makes no attempt to emulate Common Lisp multiple return | 2852 | package makes no attempt to emulate Common Lisp multiple return |
| 2852 | values; Emacs versions of Common Lisp functions that return more | 2853 | values; Emacs versions of Common Lisp functions that return more |
| 2853 | than one value either return just the first value (as in | 2854 | than 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 |
| 2856 | for the Common Lisp functions that work with multiple values, but | 2857 | for the Common Lisp functions that work with multiple values, but |
| 2857 | in Emacs Lisp these functions simply operate on lists instead. | 2858 | in Emacs Lisp these functions simply operate on lists instead. |
| 2858 | The @code{values} form, for example, is a synonym for @code{list} | 2859 | The @code{values} form, for example, is a synonym for @code{list} |
| 2859 | in Emacs. | 2860 | in 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{} |
| 2862 | This form evaluates @var{values-form}, which must return a list of | 2863 | This form evaluates @var{values-form}, which must return a list of |
| 2863 | values. It then binds the @var{var}s to these respective values, | 2864 | values. It then binds the @var{var}s to these respective values, |
| 2864 | as if by @code{let}, and then executes the body @var{forms}. | 2865 | as 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 | |||
| 2867 | values, the excess values are ignored. | 2868 | values, 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 |
| 2871 | This form evaluates @var{form}, which must return a list of values. | 2872 | This form evaluates @var{form}, which must return a list of values. |
| 2872 | It then sets the @var{var}s to these respective values, as if by | 2873 | It 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 |
| 2874 | in @code{multiple-value-bind}. | 2875 | in @code{cl-multiple-value-bind}. |
| 2875 | @end defspec | 2876 | @end defspec |
| 2876 | 2877 | ||
| 2877 | The older Quiroz package attempted a more faithful (but still | 2878 | The older Quiroz package attempted a more faithful (but still |
| 2878 | imperfect) emulation of Common Lisp multiple values. The old | 2879 | imperfect) emulation of Common Lisp multiple values. The old |
| 2879 | method ``usually'' simulated true multiple values quite well, | 2880 | method ``usually'' simulated true multiple values quite well, |
| 2880 | but under certain circumstances would leave spurious return | 2881 | but under certain circumstances would leave spurious return |
| 2881 | values in memory where a later, unrelated @code{multiple-value-bind} | 2882 | values in memory where a later, unrelated @code{cl-multiple-value-bind} |
| 2882 | form would see them. | 2883 | form would see them. |
| 2883 | 2884 | ||
| 2884 | Since a perfect emulation is not feasible in Emacs Lisp, this | 2885 | Since a perfect emulation is not feasible in Emacs Lisp, this |
| @@ -2897,7 +2898,7 @@ for @code{defmacro} due to technical difficulties. | |||
| 2897 | Destructuring is made available to the user by way of the | 2898 | Destructuring is made available to the user by way of the |
| 2898 | following macro: | 2899 | following macro: |
| 2899 | 2900 | ||
| 2900 | @defspec destructuring-bind arglist expr forms@dots{} | 2901 | @defspec cl-destructuring-bind arglist expr forms@dots{} |
| 2901 | This macro expands to code which executes @var{forms}, with | 2902 | This macro expands to code which executes @var{forms}, with |
| 2902 | the variables in @var{arglist} bound to the list of values | 2903 | the variables in @var{arglist} bound to the list of values |
| 2903 | returned by @var{expr}. The @var{arglist} can include all | 2904 | returned 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 | |||
| 2908 | or with incorrect keyword arguments. | 2909 | or with incorrect keyword arguments. |
| 2909 | @end defspec | 2910 | @end defspec |
| 2910 | 2911 | ||
| 2911 | This package also includes the Common Lisp @code{define-compiler-macro} | 2912 | This package also includes the Common Lisp @code{cl-define-compiler-macro} |
| 2912 | facility, which allows you to define compile-time expansions and | 2913 | facility, which allows you to define compile-time expansions and |
| 2913 | optimizations for your functions. | 2914 | optimizations for your functions. |
| 2914 | 2915 | ||
| 2915 | @defspec define-compiler-macro name arglist forms@dots{} | 2916 | @defspec cl-define-compiler-macro name arglist forms@dots{} |
| 2916 | This form is similar to @code{defmacro}, except that it only expands | 2917 | This form is similar to @code{defmacro}, except that it only expands |
| 2917 | calls to @var{name} at compile-time; calls processed by the Lisp | 2918 | calls to @var{name} at compile-time; calls processed by the Lisp |
| 2918 | interpreter are not expanded, nor are they expanded by the | 2919 | interpreter are not expanded, nor are they expanded by the |
| @@ -2930,25 +2931,25 @@ For example, here is a simplified version of a definition that | |||
| 2930 | appears as a standard part of this package: | 2931 | appears 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 |
| 2942 | This definition causes @code{(member* @var{a} @var{list})} to change | 2943 | This definition causes @code{(cl-member @var{a} @var{list})} to change |
| 2943 | to a call to the faster @code{memq} in the common case where @var{a} | 2944 | to a call to the faster @code{memq} in the common case where @var{a} |
| 2944 | is a non-floating-point constant; if @var{a} is anything else, or | 2945 | is a non-floating-point constant; if @var{a} is anything else, or |
| 2945 | if there are any keyword arguments in the call, then the original | 2946 | if 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 |
| 2947 | for @code{member*} optimizes a number of other cases, including | 2948 | for @code{cl-member} optimizes a number of other cases, including |
| 2948 | common @code{:test} predicates.) | 2949 | common @code{:test} predicates.) |
| 2949 | @end defspec | 2950 | @end defspec |
| 2950 | 2951 | ||
| 2951 | @defun compiler-macroexpand form | 2952 | @defun cl-compiler-macroexpand form |
| 2952 | This function is analogous to @code{macroexpand}, except that it | 2953 | This function is analogous to @code{macroexpand}, except that it |
| 2953 | expands compiler macros rather than regular macros. It returns | 2954 | expands 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 | |||
| 2958 | for which no further expansion is possible. | 2959 | for 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} |
| 2962 | and @code{symbol-macrolet} forms for making ``local'' macro | 2963 | and @code{cl-symbol-macrolet} forms for making ``local'' macro |
| 2963 | definitions. | 2964 | definitions. |
| 2964 | 2965 | ||
| 2965 | @node Declarations | 2966 | @node Declarations |
| @@ -2971,8 +2972,8 @@ mechanism that allows you to give the compiler special hints | |||
| 2971 | about the types of data that will be stored in particular variables, | 2972 | about the types of data that will be stored in particular variables, |
| 2972 | and about the ways those variables and functions will be used. This | 2973 | and about the ways those variables and functions will be used. This |
| 2973 | package defines versions of all the Common Lisp declaration forms: | 2974 | package 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}, |
| 2975 | and @code{the}. | 2976 | and @code{cl-the}. |
| 2976 | 2977 | ||
| 2977 | Most of the Common Lisp declarations are not currently useful in | 2978 | Most of the Common Lisp declarations are not currently useful in |
| 2978 | Emacs Lisp, as the byte-code system provides little opportunity | 2979 | Emacs Lisp, as the byte-code system provides little opportunity |
| @@ -2982,53 +2983,53 @@ declarations are meaningful when the optimizing byte | |||
| 2982 | compiler is being used, however. Under the earlier non-optimizing | 2983 | compiler is being used, however. Under the earlier non-optimizing |
| 2983 | compiler, these declarations will effectively be ignored. | 2984 | compiler, these declarations will effectively be ignored. |
| 2984 | 2985 | ||
| 2985 | @defun proclaim decl-spec | 2986 | @defun cl-proclaim decl-spec |
| 2986 | This function records a ``global'' declaration specified by | 2987 | This 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} |
| 2988 | is evaluated and thus should normally be quoted. | 2989 | is 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{} |
| 2992 | This macro is like @code{proclaim}, except that it takes any number | 2993 | This macro is like @code{cl-proclaim}, except that it takes any number |
| 2993 | of @var{decl-spec} arguments, and the arguments are unevaluated and | 2994 | of @var{decl-spec} arguments, and the arguments are unevaluated and |
| 2994 | unquoted. The @code{declaim} macro also puts an @code{(eval-when | 2995 | unquoted. 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 |
| 2996 | be registered at compile-time as well as at run-time. (This is vital, | 2997 | be registered at compile-time as well as at run-time. (This is vital, |
| 2997 | since normally the declarations are meant to influence the way the | 2998 | since normally the declarations are meant to influence the way the |
| 2998 | compiler treats the rest of the file that contains the @code{declaim} | 2999 | compiler treats the rest of the file that contains the @code{cl-declaim} |
| 2999 | form.) | 3000 | form.) |
| 3000 | @end defspec | 3001 | @end defspec |
| 3001 | 3002 | ||
| 3002 | @defspec declare decl-specs@dots{} | 3003 | @defspec cl-declare decl-specs@dots{} |
| 3003 | This macro is used to make declarations within functions and other | 3004 | This macro is used to make declarations within functions and other |
| 3004 | code. Common Lisp allows declarations in various locations, generally | 3005 | code. Common Lisp allows declarations in various locations, generally |
| 3005 | at the beginning of any of the many ``implicit @code{progn}s'' | 3006 | at the beginning of any of the many ``implicit @code{progn}s'' |
| 3006 | throughout Lisp syntax, such as function bodies, @code{let} bodies, | 3007 | throughout Lisp syntax, such as function bodies, @code{let} bodies, |
| 3007 | etc. Currently the only declaration understood by @code{declare} | 3008 | etc. Currently the only declaration understood by @code{cl-declare} |
| 3008 | is @code{special}. | 3009 | is @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{} |
| 3012 | In this package, @code{locally} is no different from @code{progn}. | 3013 | In 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 |
| 3016 | Type information provided by @code{the} is ignored in this package; | 3017 | Type information provided by @code{cl-the} is ignored in this package; |
| 3017 | in other words, @code{(the @var{type} @var{form})} is equivalent | 3018 | in other words, @code{(cl-the @var{type} @var{form})} is equivalent |
| 3018 | to @var{form}. Future versions of the optimizing byte-compiler may | 3019 | to @var{form}. Future versions of the optimizing byte-compiler may |
| 3019 | make use of this information. | 3020 | make use of this information. |
| 3020 | 3021 | ||
| 3021 | For example, @code{mapcar} can map over both lists and arrays. It is | 3022 | For example, @code{mapcar} can map over both lists and arrays. It is |
| 3022 | hard for the compiler to expand @code{mapcar} into an in-line loop | 3023 | hard for the compiler to expand @code{mapcar} into an in-line loop |
| 3023 | unless it knows whether the sequence will be a list or an array ahead | 3024 | unless it knows whether the sequence will be a list or an array ahead |
| 3024 | of time. With @code{(mapcar 'car (the vector foo))}, a future | 3025 | of time. With @code{(mapcar 'car (cl-the vector foo))}, a future |
| 3025 | compiler would have enough information to expand the loop in-line. | 3026 | compiler would have enough information to expand the loop in-line. |
| 3026 | For now, Emacs Lisp will treat the above code as exactly equivalent | 3027 | For now, Emacs Lisp will treat the above code as exactly equivalent |
| 3027 | to @code{(mapcar 'car foo)}. | 3028 | to @code{(mapcar 'car foo)}. |
| 3028 | @end defspec | 3029 | @end defspec |
| 3029 | 3030 | ||
| 3030 | Each @var{decl-spec} in a @code{proclaim}, @code{declaim}, or | 3031 | Each @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 |
| 3032 | what kind of declaration it is. This package currently understands | 3033 | what 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}, |
| 3034 | and @code{warn} declarations. (The @code{warn} declaration is an | 3035 | and @code{warn} declarations. (The @code{warn} declaration is an |
| @@ -3045,16 +3046,16 @@ bound in the body of the function. The compiler normally emits | |||
| 3045 | warnings for such references, since they could be typographical | 3046 | warnings for such references, since they could be typographical |
| 3046 | errors for references to local variables. | 3047 | errors for references to local variables. |
| 3047 | 3048 | ||
| 3048 | The declaration @code{(declare (special @var{var1} @var{var2}))} is | 3049 | The declaration @code{(cl-declare (special @var{var1} @var{var2}))} is |
| 3049 | equivalent to @code{(defvar @var{var1}) (defvar @var{var2})} in the | 3050 | equivalent to @code{(defvar @var{var1}) (defvar @var{var2})} in the |
| 3050 | optimizing compiler, or to nothing at all in older compilers (which | 3051 | optimizing compiler, or to nothing at all in older compilers (which |
| 3051 | do not warn for non-local references). | 3052 | do not warn for non-local references). |
| 3052 | 3053 | ||
| 3053 | In top-level contexts, it is generally better to write | 3054 | In 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}))}, |
| 3055 | since @code{defvar} makes your intentions clearer. But the older | 3056 | since @code{defvar} makes your intentions clearer. But the older |
| 3056 | byte compilers can not handle @code{defvar}s appearing inside of | 3057 | byte compilers can not handle @code{defvar}s appearing inside of |
| 3057 | functions, while @code{(declare (special @var{var}))} takes care | 3058 | functions, while @code{(cl-declare (special @var{var}))} takes care |
| 3058 | to work correctly with all compilers. | 3059 | to 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 | |||
| 3072 | and declare it inline all at once. | 3073 | and 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, | |||
| 3083 | but it is impolite to use it to request inlining of an external | 3084 | but it is impolite to use it to request inlining of an external |
| 3084 | function. | 3085 | function. |
| 3085 | 3086 | ||
| 3086 | In Common Lisp, it is possible to use @code{(declare (inline @dots{}))} | 3087 | In Common Lisp, it is possible to use @code{(cl-declare (inline @dots{}))} |
| 3087 | before a particular call to a function to cause just that call to | 3088 | before a particular call to a function to cause just that call to |
| 3088 | be inlined; the current byte compilers provide no way to implement | 3089 | be inlined; the current byte compilers provide no way to implement |
| 3089 | this, so @code{(declare (inline @dots{}))} is currently ignored by | 3090 | this, so @code{(cl-declare (inline @dots{}))} is currently ignored by |
| 3090 | this package. | 3091 | this 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 | |||
| 3107 | The default level for both qualities is 1. | 3108 | The default level for both qualities is 1. |
| 3108 | 3109 | ||
| 3109 | In this package, with the optimizing compiler, the | 3110 | In 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} |
| 3111 | flag, which is set to @code{nil} for @code{(speed 0)} and to | 3113 | flag, 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 | |||
| 3125 | just because of an error in a fully-optimized Lisp program. | 3127 | just because of an error in a fully-optimized Lisp program. |
| 3126 | 3128 | ||
| 3127 | The @code{optimize} declaration is normally used in a top-level | 3129 | The @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 |
| 3129 | it to be used with @code{declare} to set the level of optimization | 3131 | it to be used with @code{cl-declare} to set the level of optimization |
| 3130 | locally for a given form, but this will not work correctly with the | 3132 | locally for a given form, but this will not work correctly with the |
| 3131 | current version of the optimizing compiler. (The @code{declare} | 3133 | current version of the optimizing compiler. (The @code{cl-declare} |
| 3132 | will set the new optimization level, but that level will not | 3134 | will set the new optimization level, but that level will not |
| 3133 | automatically be unset after the enclosing form is done.) | 3135 | automatically be unset after the enclosing form is done.) |
| 3134 | 3136 | ||
| @@ -3152,8 +3154,8 @@ This package defines several symbol-related features that were | |||
| 3152 | missing from Emacs Lisp. | 3154 | missing 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. | |||
| 3165 | There are also functions for working with property lists as | 3167 | There are also functions for working with property lists as |
| 3166 | first-class data structures not attached to particular symbols. | 3168 | first-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 |
| 3169 | This function is like @code{get}, except that if the property is | 3171 | This function is like @code{get}, except that if the property is |
| 3170 | not found, the @var{default} argument provides the return value. | 3172 | not 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 |
| 3172 | the default; this package's @code{get*} is equivalent to Common | 3174 | the default; this package's @code{cl-get} is equivalent to Common |
| 3173 | Lisp's @code{get}.) | 3175 | Lisp's @code{get}.) |
| 3174 | 3176 | ||
| 3175 | The @code{get*} function is @code{setf}-able; when used in this | 3177 | The @code{cl-get} function is @code{setf}-able; when used in this |
| 3176 | fashion, the @var{default} argument is allowed but ignored. | 3178 | fashion, 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 |
| 3180 | This function removes the entry for @var{property} from the property | 3182 | This function removes the entry for @var{property} from the property |
| 3181 | list of @var{symbol}. It returns a true value if the property was | 3183 | list of @var{symbol}. It returns a true value if the property was |
| 3182 | indeed found and removed, or @code{nil} if there was no such property. | 3184 | indeed 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. | |||
| 3184 | since @code{get} did not allow a @var{default}, it was very difficult | 3186 | since @code{get} did not allow a @var{default}, it was very difficult |
| 3185 | to distinguish between a missing property and a property whose value | 3187 | to distinguish between a missing property and a property whose value |
| 3186 | was @code{nil}; thus, setting a property to @code{nil} was close | 3188 | was @code{nil}; thus, setting a property to @code{nil} was close |
| 3187 | enough to @code{remprop} for most purposes.) | 3189 | enough 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 |
| 3191 | This function scans the list @var{place} as if it were a property | 3193 | This function scans the list @var{place} as if it were a property |
| 3192 | list, i.e., a list of alternating property names and values. If | 3194 | list, i.e., a list of alternating property names and values. If |
| 3193 | an even-numbered element of @var{place} is found which is @code{eq} | 3195 | an even-numbered element of @var{place} is found which is @code{eq} |
| @@ -3198,7 +3200,7 @@ is given). | |||
| 3198 | In particular, | 3200 | In 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 | ||
| 3204 | It is valid to use @code{getf} as a @code{setf} place, in which case | 3206 | It 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 | |||
| 3209 | pair onto the list if the property is not yet present. | 3211 | pair 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 | ||
| 3215 | The @code{get} and @code{get*} functions are also @code{setf}-able. | 3217 | The @code{get} and @code{cl-get} functions are also @code{setf}-able. |
| 3216 | The fact that @code{default} is ignored can sometimes be useful: | 3218 | The 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 | ||
| 3222 | Here, symbol @code{foo}'s @code{usage-count} property is incremented | 3224 | Here, symbol @code{foo}'s @code{usage-count} property is incremented |
| 3223 | if it exists, or set to 1 (an incremented 0) otherwise. | 3225 | if it exists, or set to 1 (an incremented 0) otherwise. |
| 3224 | 3226 | ||
| 3227 | @c FIXME cl-getf? | ||
| 3225 | When not used as a @code{setf} form, @code{getf} is just a regular | 3228 | When not used as a @code{setf} form, @code{getf} is just a regular |
| 3226 | function and its @var{place} argument can actually be any Lisp | 3229 | function and its @var{place} argument can actually be any Lisp |
| 3227 | expression. | 3230 | expression. |
| 3228 | @end defun | 3231 | @end defun |
| 3229 | 3232 | ||
| 3230 | @defspec remf place property | 3233 | @defspec cl-remf place property |
| 3231 | This macro removes the property-value pair for @var{property} from | 3234 | This macro removes the property-value pair for @var{property} from |
| 3232 | the property list stored at @var{place}, which is any @code{setf}-able | 3235 | the property list stored at @var{place}, which is any @code{setf}-able |
| 3233 | place expression. It returns true if the property was found. Note | 3236 | place expression. It returns true if the property was found. Note |
| @@ -3248,7 +3251,7 @@ out the property and value cells. | |||
| 3248 | These functions create unique symbols, typically for use as | 3251 | These functions create unique symbols, typically for use as |
| 3249 | temporary variables. | 3252 | temporary variables. |
| 3250 | 3253 | ||
| 3251 | @defun gensym &optional x | 3254 | @defun cl-gensym &optional x |
| 3252 | This function creates a new, uninterned symbol (using @code{make-symbol}) | 3255 | This function creates a new, uninterned symbol (using @code{make-symbol}) |
| 3253 | with a unique name. (The name of an uninterned symbol is relevant | 3256 | with a unique name. (The name of an uninterned symbol is relevant |
| 3254 | only if the symbol is printed.) By default, the name is generated | 3257 | only 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 | |||
| 3260 | code. | 3263 | code. |
| 3261 | @end defun | 3264 | @end defun |
| 3262 | 3265 | ||
| 3263 | @defvar *gensym-counter* | 3266 | @defvar cl--gensym-counter |
| 3264 | This variable holds the counter used to generate @code{gensym} names. | 3267 | This variable holds the counter used to generate @code{cl-gensym} names. |
| 3265 | It is incremented after each use by @code{gensym}. In Common Lisp | 3268 | It is incremented after each use by @code{cl-gensym}. In Common Lisp |
| 3266 | this is initialized with 0, but this package initializes it with a | 3269 | this is initialized with 0, but this package initializes it with a |
| 3267 | random (time-dependent) value to avoid trouble when two files that | 3270 | random (time-dependent) value to avoid trouble when two files that |
| 3268 | each used @code{gensym} in their compilation are loaded together. | 3271 | each 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 |
| 3270 | out to a file and the Emacs loader loads them, so their names have to | 3273 | out to a file and the Emacs loader loads them, so their names have to |
| 3271 | be treated a bit more carefully than in Common Lisp where uninterned | 3274 | be treated a bit more carefully than in Common Lisp where uninterned |
| 3272 | symbols remain uninterned after loading.) | 3275 | symbols remain uninterned after loading.) |
| 3273 | @end defvar | 3276 | @end defvar |
| 3274 | 3277 | ||
| 3275 | @defun gentemp &optional x | 3278 | @defun cl-gentemp &optional x |
| 3276 | This function is like @code{gensym}, except that it produces a new | 3279 | This 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 |
| 3278 | exists, the function keeps incrementing the counter and trying | 3281 | exists, the function keeps incrementing the counter and trying |
| 3279 | again until a new symbol is generated. | 3282 | again until a new symbol is generated. |
| @@ -3294,10 +3297,10 @@ This section defines a few simple Common Lisp operations on numbers | |||
| 3294 | which were left out of Emacs Lisp. | 3297 | which 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. | |||
| 3311 | These functions return @code{t} if the specified condition is | 3314 | These functions return @code{t} if the specified condition is |
| 3312 | true of the numerical argument, or @code{nil} otherwise. | 3315 | true of the numerical argument, or @code{nil} otherwise. |
| 3313 | 3316 | ||
| 3314 | @defun plusp number | 3317 | @defun cl-plusp number |
| 3315 | This predicate tests whether @var{number} is positive. It is an | 3318 | This predicate tests whether @var{number} is positive. It is an |
| 3316 | error if the argument is not a number. | 3319 | error if the argument is not a number. |
| 3317 | @end defun | 3320 | @end defun |
| 3318 | 3321 | ||
| 3319 | @defun minusp number | 3322 | @defun cl-minusp number |
| 3320 | This predicate tests whether @var{number} is negative. It is an | 3323 | This predicate tests whether @var{number} is negative. It is an |
| 3321 | error if the argument is not a number. | 3324 | error if the argument is not a number. |
| 3322 | @end defun | 3325 | @end defun |
| 3323 | 3326 | ||
| 3324 | @defun oddp integer | 3327 | @defun cl-oddp integer |
| 3325 | This predicate tests whether @var{integer} is odd. It is an | 3328 | This predicate tests whether @var{integer} is odd. It is an |
| 3326 | error if the argument is not an integer. | 3329 | error if the argument is not an integer. |
| 3327 | @end defun | 3330 | @end defun |
| 3328 | 3331 | ||
| 3329 | @defun evenp integer | 3332 | @defun cl-evenp integer |
| 3330 | This predicate tests whether @var{integer} is even. It is an | 3333 | This predicate tests whether @var{integer} is even. It is an |
| 3331 | error if the argument is not an integer. | 3334 | error 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 |
| 3335 | This predicate tests whether @var{object} is a floating-point | 3338 | This predicate tests whether @var{object} is a floating-point |
| 3336 | number. On systems that support floating-point, this is equivalent | 3339 | number. On systems that support floating-point, this is equivalent |
| 3337 | to @code{floatp}. On other systems, this always returns @code{nil}. | 3340 | to @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 |
| 3348 | These functions perform various arithmetic operations on numbers. | 3351 | These functions perform various arithmetic operations on numbers. |
| 3349 | 3352 | ||
| 3350 | @defun gcd &rest integers | 3353 | @defun cl-gcd &rest integers |
| 3351 | This function returns the Greatest Common Divisor of the arguments. | 3354 | This function returns the Greatest Common Divisor of the arguments. |
| 3352 | For one argument, it returns the absolute value of that argument. | 3355 | For one argument, it returns the absolute value of that argument. |
| 3353 | For zero arguments, it returns zero. | 3356 | For zero arguments, it returns zero. |
| 3354 | @end defun | 3357 | @end defun |
| 3355 | 3358 | ||
| 3356 | @defun lcm &rest integers | 3359 | @defun cl-lcm &rest integers |
| 3357 | This function returns the Least Common Multiple of the arguments. | 3360 | This function returns the Least Common Multiple of the arguments. |
| 3358 | For one argument, it returns the absolute value of that argument. | 3361 | For one argument, it returns the absolute value of that argument. |
| 3359 | For zero arguments, it returns one. | 3362 | For zero arguments, it returns one. |
| 3360 | @end defun | 3363 | @end defun |
| 3361 | 3364 | ||
| 3362 | @defun isqrt integer | 3365 | @defun cl-isqrt integer |
| 3363 | This function computes the ``integer square root'' of its integer | 3366 | This function computes the ``integer square root'' of its integer |
| 3364 | argument, i.e., the greatest integer less than or equal to the true | 3367 | argument, i.e., the greatest integer less than or equal to the true |
| 3365 | square root of the argument. | 3368 | square 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 |
| 3369 | This function implements the Common Lisp @code{floor} function. | 3372 | With one argument, @code{cl-floor} returns a list of two numbers: |
| 3370 | It is called @code{floor*} to avoid name conflicts with the | ||
| 3371 | simpler @code{floor} function built-in to Emacs. | ||
| 3372 | |||
| 3373 | With one argument, @code{floor*} returns a list of two numbers: | ||
| 3374 | The argument rounded down (toward minus infinity) to an integer, | 3373 | The argument rounded down (toward minus infinity) to an integer, |
| 3375 | and the ``remainder'' which would have to be added back to the | 3374 | and the ``remainder'' which would have to be added back to the |
| 3376 | first return value to yield the argument again. If the argument | 3375 | first return value to yield the argument again. If the argument |
| @@ -3379,37 +3378,37 @@ If the argument is a floating-point number, the first | |||
| 3379 | result is a Lisp integer and the second is a Lisp float between | 3378 | result is a Lisp integer and the second is a Lisp float between |
| 3380 | 0 (inclusive) and 1 (exclusive). | 3379 | 0 (inclusive) and 1 (exclusive). |
| 3381 | 3380 | ||
| 3382 | With two arguments, @code{floor*} divides @var{number} by | 3381 | With 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 |
| 3384 | corresponding remainder as a list of two numbers. If | 3383 | corresponding 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})}, |
| 3386 | then @code{@var{q}*@var{y} + @var{r} = @var{x}}, with @var{r} | 3385 | then @code{@var{q}*@var{y} + @var{r} = @var{x}}, with @var{r} |
| 3387 | between 0 (inclusive) and @var{r} (exclusive). Also, note | 3386 | between 0 (inclusive) and @var{r} (exclusive). Also, note |
| 3388 | that @code{(floor* @var{x})} is exactly equivalent to | 3387 | that @code{(cl-floor @var{x})} is exactly equivalent to |
| 3389 | @code{(floor* @var{x} 1)}. | 3388 | @code{(cl-floor @var{x} 1)}. |
| 3390 | 3389 | ||
| 3391 | This function is entirely compatible with Common Lisp's @code{floor} | 3390 | This function is entirely compatible with Common Lisp's @code{floor} |
| 3392 | function, except that it returns the two results in a list since | 3391 | function, except that it returns the two results in a list since |
| 3393 | Emacs Lisp does not support multiple-valued functions. | 3392 | Emacs 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 |
| 3397 | This function implements the Common Lisp @code{ceiling} function, | 3396 | This function implements the Common Lisp @code{ceiling} function, |
| 3398 | which is analogous to @code{floor} except that it rounds the | 3397 | which is analogous to @code{floor} except that it rounds the |
| 3399 | argument or quotient of the arguments up toward plus infinity. | 3398 | argument or quotient of the arguments up toward plus infinity. |
| 3400 | The remainder will be between 0 and minus @var{r}. | 3399 | The 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 |
| 3404 | This function implements the Common Lisp @code{truncate} function, | 3403 | This function implements the Common Lisp @code{truncate} function, |
| 3405 | which is analogous to @code{floor} except that it rounds the | 3404 | which is analogous to @code{floor} except that it rounds the |
| 3406 | argument or quotient of the arguments toward zero. Thus it is | 3405 | argument or quotient of the arguments toward zero. Thus it is |
| 3407 | equivalent to @code{floor*} if the argument or quotient is | 3406 | equivalent to @code{cl-floor} if the argument or quotient is |
| 3408 | positive, or to @code{ceiling*} otherwise. The remainder has | 3407 | positive, or to @code{cl-ceiling} otherwise. The remainder has |
| 3409 | the same sign as @var{number}. | 3408 | the 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 |
| 3413 | This function implements the Common Lisp @code{round} function, | 3412 | This function implements the Common Lisp @code{round} function, |
| 3414 | which is analogous to @code{floor} except that it rounds the | 3413 | which is analogous to @code{floor} except that it rounds the |
| 3415 | argument or quotient of the arguments to the nearest integer. | 3414 | argument 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 | |||
| 3417 | halfway between two integers), it rounds to the even integer. | 3416 | halfway 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 |
| 3421 | This function returns the same value as the second return value | 3420 | This function returns the same value as the second return value |
| 3422 | of @code{floor}. | 3421 | of @code{cl-floor}. |
| 3423 | @end defun | 3422 | @end defun |
| 3424 | 3423 | ||
| 3425 | @defun rem* number divisor | 3424 | @defun cl-rem number divisor |
| 3426 | This function returns the same value as the second return value | 3425 | This function returns the same value as the second return value |
| 3427 | of @code{truncate}. | 3426 | of @code{cl-truncate}. |
| 3428 | @end defun | 3427 | @end defun |
| 3429 | 3428 | ||
| 3429 | @c FIXME this stuff is probably no longer of interest to anyone. | ||
| 3430 | These definitions are compatible with those in the Quiroz | 3430 | These 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 |
| 3432 | to certain function names to avoid conflicts with existing | 3432 | @c this package appends @samp{*} to certain function names to avoid |
| 3433 | Emacs functions, and that the mechanism for returning | 3433 | @c conflicts with existing Emacs functions, and that |
| 3434 | multiple values is different. | 3434 | the 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 | |||
| 3447 | random numbers than the simple generators supplied by many | 3447 | random numbers than the simple generators supplied by many |
| 3448 | operating systems. | 3448 | operating systems. |
| 3449 | 3449 | ||
| 3450 | @defun random* number &optional state | 3450 | @defun cl-random number &optional state |
| 3451 | This function returns a random nonnegative number less than | 3451 | This 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). |
| 3453 | The @var{state} argument should be a @code{random-state} object | 3453 | The @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 |
| 3462 | This variable contains the system ``default'' @code{random-state} | 3462 | This variable contains the system ``default'' @code{random-state} |
| 3463 | object, used for calls to @code{random*} that do not specify an | 3463 | object, used for calls to @code{cl-random} that do not specify an |
| 3464 | alternative state object. Since any number of programs in the | 3464 | alternative state object. Since any number of programs in the |
| 3465 | Emacs process may be accessing @code{*random-state*} in interleaved | 3465 | Emacs process may be accessing @code{cl--random-state} in interleaved |
| 3466 | fashion, the sequence generated from this variable will be | 3466 | fashion, the sequence generated from this variable will be |
| 3467 | irreproducible for all intents and purposes. | 3467 | irreproducible 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 |
| 3471 | This function creates or copies a @code{random-state} object. | 3471 | This function creates or copies a @code{random-state} object. |
| 3472 | If @var{state} is omitted or @code{nil}, it returns a new copy of | 3472 | If @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 |
| 3474 | sequences of calls to @code{(random* @var{n})} and | 3474 | sequences 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 |
| 3476 | random-state object) will return identical sequences of random | 3476 | random-state object) will return identical sequences of random |
| 3477 | numbers. | 3477 | numbers. |
| 3478 | 3478 | ||
| @@ -3487,13 +3487,13 @@ different sequence of random numbers. | |||
| 3487 | It is valid to print a @code{random-state} object to a buffer or | 3487 | It is valid to print a @code{random-state} object to a buffer or |
| 3488 | file and later read it back with @code{read}. If a program wishes | 3488 | file and later read it back with @code{read}. If a program wishes |
| 3489 | to use a sequence of pseudo-random numbers which can be reproduced | 3489 | to use a sequence of pseudo-random numbers which can be reproduced |
| 3490 | later for debugging, it can call @code{(make-random-state t)} to | 3490 | later for debugging, it can call @code{(cl-make-random-state t)} to |
| 3491 | get a new sequence, then print this sequence to a file. When the | 3491 | get a new sequence, then print this sequence to a file. When the |
| 3492 | program is later rerun, it can read the original run's random-state | 3492 | program is later rerun, it can read the original run's random-state |
| 3493 | from the file. | 3493 | from the file. |
| 3494 | @end defun | 3494 | @end defun |
| 3495 | 3495 | ||
| 3496 | @defun random-state-p object | 3496 | @defun cl-random-state-p object |
| 3497 | This predicate returns @code{t} if @var{object} is a | 3497 | This 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 |
| 3514 | This function makes sure that the Common Lisp floating-point parameters | 3514 | This function makes sure that the Common Lisp floating-point parameters |
| 3515 | like @code{most-positive-float} have been initialized. Until it is | 3515 | like @code{cl-most-positive-float} have been initialized. Until it is |
| 3516 | called, these parameters will be @code{nil}. If this version of Emacs | 3516 | called, these parameters will be @code{nil}. If this version of Emacs |
| 3517 | does not support floats, the parameters will remain @code{nil}. If the | 3517 | does not support floats, the parameters will remain @code{nil}. If the |
| 3518 | parameters have already been initialized, the function returns | 3518 | parameters have already been initialized, the function returns |
| @@ -3530,50 +3530,50 @@ precisions, it has families of constants like | |||
| 3530 | floating-point precision, so this package omits the precision word | 3530 | floating-point precision, so this package omits the precision word |
| 3531 | from the constants' names. | 3531 | from the constants' names. |
| 3532 | 3532 | ||
| 3533 | @defvar most-positive-float | 3533 | @defvar cl-most-positive-float |
| 3534 | This constant equals the largest value a Lisp float can hold. | 3534 | This constant equals the largest value a Lisp float can hold. |
| 3535 | For those systems whose arithmetic supports infinities, this is | 3535 | For those systems whose arithmetic supports infinities, this is |
| 3536 | the largest @emph{finite} value. For IEEE machines, the value | 3536 | the largest @emph{finite} value. For IEEE machines, the value |
| 3537 | is approximately @code{1.79e+308}. | 3537 | is approximately @code{1.79e+308}. |
| 3538 | @end defvar | 3538 | @end defvar |
| 3539 | 3539 | ||
| 3540 | @defvar most-negative-float | 3540 | @defvar cl-most-negative-float |
| 3541 | This constant equals the most-negative value a Lisp float can hold. | 3541 | This 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 |
| 3546 | This constant equals the smallest Lisp float value greater than zero. | 3546 | This constant equals the smallest Lisp float value greater than zero. |
| 3547 | For IEEE machines, it is about @code{4.94e-324} if denormals are | 3547 | For IEEE machines, it is about @code{4.94e-324} if denormals are |
| 3548 | supported or @code{2.22e-308} if not. | 3548 | supported 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 |
| 3552 | This constant equals the smallest @emph{normalized} Lisp float greater | 3552 | This constant equals the smallest @emph{normalized} Lisp float greater |
| 3553 | than zero, i.e., the smallest value for which IEEE denormalization | 3553 | than zero, i.e., the smallest value for which IEEE denormalization |
| 3554 | will not result in a loss of precision. For IEEE machines, this | 3554 | will not result in a loss of precision. For IEEE machines, this |
| 3555 | value is about @code{2.22e-308}. For machines that do not support | 3555 | value is about @code{2.22e-308}. For machines that do not support |
| 3556 | the concept of denormalization and gradual underflow, this constant | 3556 | the concept of denormalization and gradual underflow, this constant |
| 3557 | will always equal @code{least-positive-float}. | 3557 | will 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 |
| 3561 | This constant is the negative counterpart of @code{least-positive-float}. | 3561 | This 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 |
| 3565 | This constant is the negative counterpart of | 3565 | This 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 |
| 3570 | This constant is the smallest positive Lisp float that can be added | 3570 | This constant is the smallest positive Lisp float that can be added |
| 3571 | to 1.0 to produce a distinct value. Adding a smaller number to 1.0 | 3571 | to 1.0 to produce a distinct value. Adding a smaller number to 1.0 |
| 3572 | will yield 1.0 again due to roundoff. For IEEE machines, epsilon | 3572 | will yield 1.0 again due to roundoff. For IEEE machines, epsilon |
| 3573 | is about @code{2.22e-16}. | 3573 | is about @code{2.22e-16}. |
| 3574 | @end defvar | 3574 | @end defvar |
| 3575 | 3575 | ||
| 3576 | @defvar float-negative-epsilon | 3576 | @defvar cl-float-negative-epsilon |
| 3577 | This is the smallest positive value that can be subtracted from | 3577 | This is the smallest positive value that can be subtracted from |
| 3578 | 1.0 to produce a distinct value. For IEEE machines, it is about | 3578 | 1.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. | |||
| 3607 | The @code{:key} argument should be passed either @code{nil}, or a | 3607 | The @code{:key} argument should be passed either @code{nil}, or a |
| 3608 | function of one argument. This key function is used as a filter | 3608 | function of one argument. This key function is used as a filter |
| 3609 | through which the elements of the sequence are seen; for example, | 3609 | through 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)}: |
| 3611 | It searches for an element of the list whose @code{car} equals | 3611 | It 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. |
| 3613 | If @code{:key} is omitted or @code{nil}, the filter is effectively | 3613 | If @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 | |||
| 3662 | on side effects of these functions. For example, @code{:from-end} | 3662 | on side effects of these functions. For example, @code{:from-end} |
| 3663 | may cause the sequence to be scanned actually in reverse, or it may | 3663 | may cause the sequence to be scanned actually in reverse, or it may |
| 3664 | be scanned forwards but computing a result ``as if'' it were scanned | 3664 | be scanned forwards but computing a result ``as if'' it were scanned |
| 3665 | backwards. (Some functions, like @code{mapcar*} and @code{every}, | 3665 | backwards. (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 |
| 3667 | so side effects are perfectly acceptable in those cases.) | 3667 | so side effects are perfectly acceptable in those cases.) |
| 3668 | 3668 | ||
| 3669 | Strings may contain ``text properties'' as well | 3669 | Strings may contain ``text properties'' as well |
| 3670 | as character data. Except as noted, it is undefined whether or | 3670 | as character data. Except as noted, it is undefined whether or |
| 3671 | not text properties are preserved by sequence functions. For | 3671 | not text properties are preserved by sequence functions. For |
| 3672 | example, @code{(remove* ?A @var{str})} may or may not preserve | 3672 | example, @code{(cl-remove ?A @var{str})} may or may not preserve |
| 3673 | the properties of the characters copied from @var{str} into the | 3673 | the properties of the characters copied from @var{str} into the |
| 3674 | result. | 3674 | result. |
| 3675 | 3675 | ||
| @@ -3681,7 +3681,7 @@ These functions ``map'' the function you specify over the elements | |||
| 3681 | of lists or arrays. They are all variations on the theme of the | 3681 | of lists or arrays. They are all variations on the theme of the |
| 3682 | built-in function @code{mapcar}. | 3682 | built-in function @code{mapcar}. |
| 3683 | 3683 | ||
| 3684 | @defun mapcar* function seq &rest more-seqs | 3684 | @defun cl-mapcar function seq &rest more-seqs |
| 3685 | This function calls @var{function} on successive parallel sets of | 3685 | This function calls @var{function} on successive parallel sets of |
| 3686 | elements from its argument sequences. Given a single @var{seq} | 3686 | elements from its argument sequences. Given a single @var{seq} |
| 3687 | argument it is equivalent to @code{mapcar}; given @var{n} sequences, | 3687 | argument it is equivalent to @code{mapcar}; given @var{n} sequences, |
| @@ -3694,86 +3694,87 @@ is always a list. | |||
| 3694 | 3694 | ||
| 3695 | Common Lisp's @code{mapcar} accepts multiple arguments but works | 3695 | Common Lisp's @code{mapcar} accepts multiple arguments but works |
| 3696 | only on lists; Emacs Lisp's @code{mapcar} accepts a single sequence | 3696 | only on lists; Emacs Lisp's @code{mapcar} accepts a single sequence |
| 3697 | argument. This package's @code{mapcar*} works as a compatible | 3697 | argument. This package's @code{cl-mapcar} works as a compatible |
| 3698 | superset of both. | 3698 | superset 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 |
| 3702 | This function maps @var{function} over the argument sequences, | 3702 | This function maps @var{function} over the argument sequences, |
| 3703 | just like @code{mapcar*}, but it returns a sequence of type | 3703 | just 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 |
| 3705 | be one of the following symbols: @code{vector}, @code{string}, | 3705 | be 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 |
| 3708 | thrown away and @code{map} returns @code{nil}). | 3708 | thrown 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 |
| 3712 | This function calls @var{function} on each of its argument lists, | 3712 | This function calls @var{function} on each of its argument lists, |
| 3713 | then on the @code{cdr}s of those lists, and so on, until the | 3713 | then on the @code{cdr}s of those lists, and so on, until the |
| 3714 | shortest list runs out. The results are returned in the form | 3714 | shortest list runs out. The results are returned in the form |
| 3715 | of a list. Thus, @code{maplist} is like @code{mapcar*} except | 3715 | of a list. Thus, @code{cl-maplist} is like @code{cl-mapcar} except |
| 3716 | that it passes in the list pointers themselves rather than the | 3716 | that 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 |
| 3721 | This function is like @code{mapcar*}, except that the values returned | 3722 | This function is like @code{cl-mapcar}, except that the values returned |
| 3722 | by @var{function} are ignored and thrown away rather than being | 3723 | by @var{function} are ignored and thrown away rather than being |
| 3723 | collected into a list. The return value of @code{cl-mapc} is @var{seq}, | 3724 | collected into a list. The return value of @code{cl-mapc} is @var{seq}, |
| 3724 | the first sequence. This function is more general than the Emacs | 3725 | the first sequence. This function is more general than the Emacs |
| 3725 | primitive @code{mapc}. | 3726 | primitive @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 |
| 3729 | This function is like @code{maplist}, except that it throws away | 3730 | This function is like @code{cl-maplist}, except that it throws away |
| 3730 | the values returned by @var{function}. | 3731 | the 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 |
| 3734 | This function is like @code{mapcar*}, except that it concatenates | 3735 | This function is like @code{cl-mapcar}, except that it concatenates |
| 3735 | the return values (which must be lists) using @code{nconc}, | 3736 | the return values (which must be lists) using @code{nconc}, |
| 3736 | rather than simply collecting them into a list. | 3737 | rather 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 |
| 3740 | This function is like @code{maplist}, except that it concatenates | 3741 | This function is like @code{cl-maplist}, except that it concatenates |
| 3741 | the return values using @code{nconc}. | 3742 | the 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 |
| 3745 | This function calls @var{predicate} on each element of @var{seq} | 3746 | This function calls @var{predicate} on each element of @var{seq} |
| 3746 | in turn; if @var{predicate} returns a non-@code{nil} value, | 3747 | in 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}. |
| 3748 | Given several sequence arguments, it steps through the sequences | 3749 | Given several sequence arguments, it steps through the sequences |
| 3749 | in parallel until the shortest one runs out, just as in | 3750 | in 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 |
| 3751 | the elements are visited, and on the fact that mapping stops | 3752 | the elements are visited, and on the fact that mapping stops |
| 3752 | immediately as soon as @var{predicate} returns non-@code{nil}. | 3753 | immediately 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 |
| 3756 | This function calls @var{predicate} on each element of the sequence(s) | 3757 | This function calls @var{predicate} on each element of the sequence(s) |
| 3757 | in turn; it returns @code{nil} as soon as @var{predicate} returns | 3758 | in 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 |
| 3759 | for all elements. | 3760 | for 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 |
| 3763 | This function calls @var{predicate} on each element of the sequence(s) | 3764 | This function calls @var{predicate} on each element of the sequence(s) |
| 3764 | in turn; it returns @code{nil} as soon as @var{predicate} returns | 3765 | in turn; it returns @code{nil} as soon as @var{predicate} returns |
| 3765 | a non-@code{nil} value for any element, or @code{t} if the predicate | 3766 | a non-@code{nil} value for any element, or @code{t} if the predicate |
| 3766 | was @code{nil} for all elements. | 3767 | was @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 |
| 3770 | This function calls @var{predicate} on each element of the sequence(s) | 3771 | This function calls @var{predicate} on each element of the sequence(s) |
| 3771 | in turn; it returns a non-@code{nil} value as soon as @var{predicate} | 3772 | in turn; it returns a non-@code{nil} value as soon as @var{predicate} |
| 3772 | returns @code{nil} for any element, or @code{t} if the predicate was | 3773 | returns @code{nil} for any element, or @code{t} if the predicate was |
| 3773 | true for all elements. | 3774 | true 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} |
| 3777 | This function combines the elements of @var{seq} using an associative | 3778 | This function combines the elements of @var{seq} using an associative |
| 3778 | binary operation. Suppose @var{function} is @code{*} and @var{seq} is | 3779 | binary operation. Suppose @var{function} is @code{*} and @var{seq} is |
| 3779 | the list @code{(2 3 4 5)}. The first two elements of the list are | 3780 | the 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 | |||
| 3781 | element, @code{(* 6 4) = 24}, and that is combined with the final | 3782 | element, @code{(* 6 4) = 24}, and that is combined with the final |
| 3782 | element: @code{(* 24 5) = 120}. Note that the @code{*} function happens | 3783 | element: @code{(* 24 5) = 120}. Note that the @code{*} function happens |
| 3783 | to be self-reducing, so that @code{(* 2 3 4 5)} has the same effect as | 3784 | to be self-reducing, so that @code{(* 2 3 4 5)} has the same effect as |
| 3784 | an explicit call to @code{reduce}. | 3785 | an explicit call to @code{cl-reduce}. |
| 3785 | 3786 | ||
| 3786 | If @code{:from-end} is true, the reduction is right-associative instead | 3787 | If @code{:from-end} is true, the reduction is right-associative instead |
| 3787 | of left-associative: | 3788 | of 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 | ||
| 3796 | If @code{:key} is specified, it is a function of one argument which | 3797 | If @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 | ||
| 3809 | All of these mapping operations can be expressed conveniently in | 3810 | All of these mapping operations can be expressed conveniently in |
| 3810 | terms of the @code{loop} macro. In compiled code, @code{loop} will | 3811 | terms of the @code{cl-loop} macro. In compiled code, @code{cl-loop} will |
| 3811 | be faster since it generates the loop as in-line code with no | 3812 | be faster since it generates the loop as in-line code with no |
| 3812 | function calls. | 3813 | function calls. |
| 3813 | 3814 | ||
| @@ -3818,7 +3819,7 @@ function calls. | |||
| 3818 | This section describes a number of Common Lisp functions for | 3819 | This section describes a number of Common Lisp functions for |
| 3819 | operating on sequences. | 3820 | operating on sequences. |
| 3820 | 3821 | ||
| 3821 | @defun subseq sequence start &optional end | 3822 | @defun cl-subseq sequence start &optional end |
| 3822 | This function returns a given subsequence of the argument | 3823 | This 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. |
| 3824 | The indices @var{start} and @var{end} must be in range, and | 3825 | The indices @var{start} and @var{end} must be in range, and |
| @@ -3830,30 +3831,30 @@ with @var{sequence}. | |||
| 3830 | As an extension to Common Lisp, @var{start} and/or @var{end} | 3831 | As an extension to Common Lisp, @var{start} and/or @var{end} |
| 3831 | may be negative, in which case they represent a distance back | 3832 | may be negative, in which case they represent a distance back |
| 3832 | from the end of the sequence. This is for compatibility with | 3833 | from the end of the sequence. This is for compatibility with |
| 3833 | Emacs's @code{substring} function. Note that @code{subseq} is | 3834 | Emacs's @code{substring} function. Note that @code{cl-subseq} is |
| 3834 | the @emph{only} sequence function that allows negative | 3835 | the @emph{only} sequence function that allows negative |
| 3835 | @var{start} and @var{end}. | 3836 | @var{start} and @var{end}. |
| 3836 | 3837 | ||
| 3837 | You can use @code{setf} on a @code{subseq} form to replace a | 3838 | You can use @code{setf} on a @code{cl-subseq} form to replace a |
| 3838 | specified range of elements with elements from another sequence. | 3839 | specified range of elements with elements from another sequence. |
| 3839 | The replacement is done as if by @code{replace}, described below. | 3840 | The 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 |
| 3843 | This function concatenates the argument sequences together to | 3844 | This function concatenates the argument sequences together to |
| 3844 | form a result sequence of type @var{result-type}, one of the | 3845 | form a result sequence of type @var{result-type}, one of the |
| 3845 | symbols @code{vector}, @code{string}, or @code{list}. The | 3846 | symbols @code{vector}, @code{string}, or @code{list}. The |
| 3846 | arguments are always copied, even in cases such as | 3847 | arguments 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 |
| 3848 | identical to an argument. | 3849 | identical 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} |
| 3852 | This function fills the elements of the sequence (or the specified | 3853 | This function fills the elements of the sequence (or the specified |
| 3853 | part of the sequence) with the value @var{item}. | 3854 | part 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} |
| 3857 | This function copies part of @var{seq2} into part of @var{seq1}. | 3858 | This function copies part of @var{seq2} into part of @var{seq1}. |
| 3858 | The sequence @var{seq1} is not stretched or resized; the amount | 3859 | The sequence @var{seq1} is not stretched or resized; the amount |
| 3859 | of data copied is simply the shorter of the source and destination | 3860 | of data copied is simply the shorter of the source and destination |
| @@ -3867,7 +3868,7 @@ start and end arguments specify overlapping regions, the effect | |||
| 3867 | is undefined. | 3868 | is 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} |
| 3871 | This returns a copy of @var{seq} with all elements matching | 3872 | This 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 | |||
| 3884 | if @var{count} was also specified). | 3885 | if @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} |
| 3888 | This deletes all elements of @var{seq} which match @var{item}. | 3889 | This deletes all elements of @var{seq} which match @var{item}. |
| 3889 | It is a destructive operation. Since Emacs Lisp does not support | 3890 | It is a destructive operation. Since Emacs Lisp does not support |
| 3890 | stretchable strings or vectors, this is the same as @code{remove*} | 3891 | stretchable strings or vectors, this is the same as @code{cl-remove} |
| 3891 | for those sequence types. On lists, @code{remove*} will copy the | 3892 | for those sequence types. On lists, @code{cl-remove} will copy the |
| 3892 | list if necessary to preserve the original list, whereas | 3893 | list 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. |
| 3894 | Compare @code{append} and @code{nconc}, which are analogous | 3895 | Compare @code{append} and @code{nconc}, which are analogous |
| 3895 | non-destructive and destructive list operations in Emacs Lisp. | 3896 | non-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 |
| 3902 | The predicate-oriented functions @code{remove-if}, @code{remove-if-not}, | 3903 | The 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} |
| 3906 | This function returns a copy of @var{seq} with duplicate elements | 3907 | This function returns a copy of @var{seq} with duplicate elements |
| 3907 | removed. Specifically, if two elements from the sequence match | 3908 | removed. Specifically, if two elements from the sequence match |
| 3908 | according to the @code{:test}, @code{:test-not}, and @code{:key} | 3909 | according 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 | |||
| 3912 | examined or removed. | 3913 | examined 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} |
| 3916 | This function deletes duplicate elements from @var{seq}. It is | 3917 | This function deletes duplicate elements from @var{seq}. It is |
| 3917 | a destructive version of @code{remove-duplicates}. | 3918 | a 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} |
| 3921 | This function returns a copy of @var{seq}, with all elements | 3922 | This function returns a copy of @var{seq}, with all elements |
| 3922 | matching @var{old} replaced with @var{new}. The @code{:count}, | 3923 | matching @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 |
| 3924 | used to limit the number of substitutions made. | 3925 | used 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} |
| 3928 | This is a destructive version of @code{substitute}; it performs | 3929 | This is a destructive version of @code{cl-substitute}; it performs |
| 3929 | the substitution using @code{setcar} or @code{aset} rather than | 3930 | the substitution using @code{setcar} or @code{aset} rather than |
| 3930 | by returning a changed copy of the sequence. | 3931 | by 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 |
| 3937 | The @code{substitute-if}, @code{substitute-if-not}, @code{nsubstitute-if}, | 3938 | The @code{cl-substitute-if}, @code{cl-substitute-if-not}, @code{cl-nsubstitute-if}, |
| 3938 | and @code{nsubstitute-if-not} functions are defined similarly. For | 3939 | and @code{cl-nsubstitute-if-not} functions are defined similarly. For |
| 3939 | these, a @var{predicate} is given in place of the @var{old} argument. | 3940 | these, 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 |
| 3945 | These functions search for elements or subsequences in a sequence. | 3946 | These 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} |
| 3949 | This function searches @var{seq} for an element matching @var{item}. | 3950 | This function searches @var{seq} for an element matching @var{item}. |
| 3950 | If it finds a match, it returns the matching element. Otherwise, | 3951 | If it finds a match, it returns the matching element. Otherwise, |
| 3951 | it returns @code{nil}. It returns the leftmost match, unless | 3952 | it 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 | |||
| 3954 | limit the range of elements that are searched. | 3955 | limit 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} |
| 3958 | This function is like @code{find}, except that it returns the | 3959 | This function is like @code{cl-find}, except that it returns the |
| 3959 | integer position in the sequence of the matching item rather than | 3960 | integer position in the sequence of the matching item rather than |
| 3960 | the item itself. The position is relative to the start of the | 3961 | the item itself. The position is relative to the start of the |
| 3961 | sequence as a whole, even if @code{:start} is non-zero. The function | 3962 | sequence as a whole, even if @code{:start} is non-zero. The function |
| 3962 | returns @code{nil} if no matching element was found. | 3963 | returns @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} |
| 3966 | This function returns the number of elements of @var{seq} which | 3967 | This function returns the number of elements of @var{seq} which |
| 3967 | match @var{item}. The result is always a nonnegative integer. | 3968 | match @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 |
| 3976 | The @code{find-if}, @code{find-if-not}, @code{position-if}, | 3977 | The @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} |
| 3978 | functions are defined similarly. | 3979 | functions 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} |
| 3981 | This function compares the specified parts of @var{seq1} and | 3982 | This 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 |
| 3983 | elements match (according to @code{:test}, @code{:test-not}, | 3984 | elements 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})}. | |||
| 3992 | If the sequences differ, then one plus the index of the rightmost | 3993 | If the sequences differ, then one plus the index of the rightmost |
| 3993 | difference (relative to @var{seq1}) is returned. | 3994 | difference (relative to @var{seq1}) is returned. |
| 3994 | 3995 | ||
| 3995 | An interesting example is @code{(mismatch str1 str2 :key 'upcase)}, | 3996 | An interesting example is @code{(cl-mismatch str1 str2 :key 'upcase)}, |
| 3996 | which compares two strings case-insensitively. | 3997 | which 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} |
| 4000 | This function searches @var{seq2} for a subsequence that matches | 4001 | This 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} |
| 4014 | This function sorts @var{seq} into increasing order as determined | 4015 | This function sorts @var{seq} into increasing order as determined |
| 4015 | by using @var{predicate} to compare pairs of elements. @var{predicate} | 4016 | by using @var{predicate} to compare pairs of elements. @var{predicate} |
| 4016 | should return true (non-@code{nil}) if and only if its first argument | 4017 | should 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 | |||
| 4025 | fed to the @var{predicate} function. For example, | 4026 | fed 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 | |||
| 4035 | simple accessor though, it's used heavily in the current | 4036 | simple accessor though, it's used heavily in the current |
| 4036 | implementation. | 4037 | implementation. |
| 4037 | 4038 | ||
| 4038 | The @code{sort*} function is destructive; it sorts lists by actually | 4039 | The @code{cl-sort} function is destructive; it sorts lists by actually |
| 4039 | rearranging the @code{cdr} pointers in suitable fashion. | 4040 | rearranging 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} |
| 4043 | This function sorts @var{seq} @dfn{stably}, meaning two elements | 4044 | This function sorts @var{seq} @dfn{stably}, meaning two elements |
| 4044 | which are equal in terms of @var{predicate} are guaranteed not to | 4045 | which are equal in terms of @var{predicate} are guaranteed not to |
| 4045 | be rearranged out of their original order by the sort. | 4046 | be rearranged out of their original order by the sort. |
| 4046 | 4047 | ||
| 4047 | In practice, @code{sort*} and @code{stable-sort} are equivalent | 4048 | In practice, @code{cl-sort} and @code{cl-stable-sort} are equivalent |
| 4048 | in Emacs Lisp because the underlying @code{sort} function is | 4049 | in Emacs Lisp because the underlying @code{sort} function is |
| 4049 | stable by default. However, this package reserves the right to | 4050 | stable by default. However, this package reserves the right to |
| 4050 | use non-stable methods for @code{sort*} in the future. | 4051 | use 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} |
| 4054 | This function merges two sequences @var{seq1} and @var{seq2} by | 4055 | This function merges two sequences @var{seq1} and @var{seq2} by |
| 4055 | interleaving their elements. The result sequence, of type @var{type} | 4056 | interleaving 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 |
| 4057 | of the lengths of the two input sequences. The sequences may be | 4058 | of the lengths of the two input sequences. The sequences may be |
| 4058 | modified destructively. Order of elements within @var{seq1} and | 4059 | modified 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 | |||
| 4073 | The functions described here operate on lists. | 4074 | The 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. | |||
| 4086 | This section describes a number of simple operations on lists, | 4087 | This section describes a number of simple operations on lists, |
| 4087 | i.e., chains of cons cells. | 4088 | i.e., chains of cons cells. |
| 4088 | 4089 | ||
| 4089 | @defun caddr x | 4090 | @defun cl-caddr x |
| 4090 | This function is equivalent to @code{(car (cdr (cdr @var{x})))}. | 4091 | This function is equivalent to @code{(car (cdr (cdr @var{x})))}. |
| 4091 | Likewise, this package defines all 28 @code{c@var{xxx}r} functions | 4092 | Likewise, this package defines all 28 @code{c@var{xxx}r} functions |
| 4092 | where @var{xxx} is up to four @samp{a}s and/or @samp{d}s. | 4093 | where @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 | |||
| 4094 | are expanded inline by the byte-compiler for maximum efficiency. | 4095 | are 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 |
| 4098 | This function is a synonym for @code{(car @var{x})}. Likewise, | 4099 | This function is a synonym for @code{(car @var{x})}. Likewise, |
| 4099 | the functions @code{second}, @code{third}, @dots{}, through | 4100 | the 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 |
| 4104 | This function is a synonym for @code{(cdr @var{x})}. | 4105 | This 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 |
| 4108 | Common Lisp defines this function to act like @code{null}, but | 4109 | Common Lisp defines this function to act like @code{null}, but |
| 4109 | signaling an error if @code{x} is neither a @code{nil} nor a | 4110 | signaling an error if @code{x} is neither a @code{nil} nor a |
| 4110 | cons cell. This package simply defines @code{endp} as a synonym | 4111 | cons cell. This package simply defines @code{cl-endp} as a synonym |
| 4111 | for @code{null}. | 4112 | for @code{null}. |
| 4112 | @end defun | 4113 | @end defun |
| 4113 | 4114 | ||
| 4114 | @defun list-length x | 4115 | @defun cl-list-length x |
| 4115 | This function returns the length of list @var{x}, exactly like | 4116 | This 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 |
| 4117 | list (where the cdr-chain forms a loop rather than terminating | 4118 | list (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 |
| 4123 | This function constructs a list of its arguments. The final | 4124 | This function constructs a list of its arguments. The final |
| 4124 | argument becomes the @code{cdr} of the last cell constructed. | 4125 | argument becomes the @code{cdr} of the last cell constructed. |
| 4125 | Thus, @code{(list* @var{a} @var{b} @var{c})} is equivalent to | 4126 | Thus, @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 | ||
| 4131 | Lisp; it is not a name invented for this package like @code{member*} | ||
| 4132 | or @code{defun*}.) | ||
| 4133 | @end defun | 4130 | @end defun |
| 4134 | 4131 | ||
| 4135 | @defun ldiff list sublist | 4132 | @defun cl-ldiff list sublist |
| 4136 | If @var{sublist} is a sublist of @var{list}, i.e., is @code{eq} to | 4133 | If @var{sublist} is a sublist of @var{list}, i.e., is @code{eq} to |
| 4137 | one of the cons cells of @var{list}, then this function returns | 4134 | one of the cons cells of @var{list}, then this function returns |
| 4138 | a copy of the part of @var{list} up to but not including | 4135 | a 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 |
| 4140 | the first two elements of the list @code{x}. The result is a | 4137 | the first two elements of the list @code{x}. The result is a |
| 4141 | copy; the original @var{list} is not modified. If @var{sublist} | 4138 | copy; the original @var{list} is not modified. If @var{sublist} |
| 4142 | is not a sublist of @var{list}, a copy of the entire @var{list} | 4139 | is not a sublist of @var{list}, a copy of the entire @var{list} |
| 4143 | is returned. | 4140 | is returned. |
| 4144 | @end defun | 4141 | @end defun |
| 4145 | 4142 | ||
| 4146 | @defun copy-list list | 4143 | @defun cl-copy-list list |
| 4147 | This function returns a copy of the list @var{list}. It copies | 4144 | This function returns a copy of the list @var{list}. It copies |
| 4148 | dotted lists like @code{(1 2 . 3)} correctly. | 4145 | dotted 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 |
| 4152 | This function returns a copy of the tree of cons cells @var{x}. | 4149 | This function returns a copy of the tree of cons cells @var{x}. |
| 4153 | Unlike @code{copy-sequence} (and its alias @code{copy-list}), | 4150 | @c FIXME? cl-copy-list is not an alias of copy-sequence. |
| 4151 | Unlike @code{copy-sequence} (and its alias @code{cl-copy-list}), | ||
| 4154 | which copies only along the @code{cdr} direction, this function | 4152 | which copies only along the @code{cdr} direction, this function |
| 4155 | copies (recursively) along both the @code{car} and the @code{cdr} | 4153 | copies (recursively) along both the @code{car} and the @code{cdr} |
| 4156 | directions. If @var{x} is not a cons cell, the function simply | 4154 | directions. 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 | |||
| 4159 | cons cells. | 4157 | cons 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} |
| 4163 | This function compares two trees of cons cells. If @var{x} and | 4161 | This 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 |
| 4165 | compared recursively. If neither @var{x} nor @var{y} is a cons | 4163 | compared 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 |
| 4179 | These functions substitute elements throughout a tree of cons | 4177 | These functions substitute elements throughout a tree of cons |
| 4180 | cells. (@xref{Sequence Functions}, for the @code{substitute} | 4178 | cells. (@xref{Sequence Functions}, for the @code{cl-substitute} |
| 4181 | function, which works on just the top-level elements of a list.) | 4179 | function, 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} |
| 4184 | This function substitutes occurrences of @var{old} with @var{new} | 4182 | This function substitutes occurrences of @var{old} with @var{new} |
| 4185 | in @var{tree}, a tree of cons cells. It returns a substituted | 4183 | in @var{tree}, a tree of cons cells. It returns a substituted |
| 4186 | tree, which will be a copy except that it may share storage with | 4184 | tree, 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 | |||
| 4195 | but not to @var{old}. | 4193 | but 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} |
| 4199 | This function is like @code{subst}, except that it works by | 4197 | This function is like @code{cl-subst}, except that it works by |
| 4200 | destructive modification (by @code{setcar} or @code{setcdr}) | 4198 | destructive modification (by @code{setcar} or @code{setcdr}) |
| 4201 | rather than copying. | 4199 | rather 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 |
| 4208 | The @code{subst-if}, @code{subst-if-not}, @code{nsubst-if}, and | 4206 | The @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} |
| 4212 | This function is like @code{subst}, except that it takes an | 4210 | This function is like @code{cl-subst}, except that it takes an |
| 4213 | association list @var{alist} of @var{old}-@var{new} pairs. | 4211 | association list @var{alist} of @var{old}-@var{new} pairs. |
| 4214 | Each element of the tree (after applying the @code{:key} | 4212 | Each element of the tree (after applying the @code{:key} |
| 4215 | function, if any), is compared with the @code{car}s of | 4213 | function, 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} |
| 4221 | This is a destructive version of @code{sublis}. | 4219 | This 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}. | |||
| 4228 | These functions perform operations on lists which represent sets | 4226 | These functions perform operations on lists which represent sets |
| 4229 | of elements. | 4227 | of 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} |
| 4232 | This function searches @var{list} for an element matching @var{item}. | 4230 | This function searches @var{list} for an element matching @var{item}. |
| 4233 | If a match is found, it returns the cons cell whose @code{car} was | 4231 | If a match is found, it returns the cons cell whose @code{car} was |
| 4234 | the matching element. Otherwise, it returns @code{nil}. Elements | 4232 | the 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 | ||
| 4239 | Note that this function's name is suffixed by @samp{*} to avoid | 4237 | The standard Emacs lisp function @code{member} uses @code{equal} for |
| 4240 | the incompatible @code{member} function defined in Emacs. | 4238 | comparisons; 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)}. |
| 4242 | to @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 |
| 4247 | The @code{member-if} and @code{member-if-not} functions | 4244 | The @code{cl-member-if} and @code{cl-member-if-not} functions |
| 4248 | analogously search for elements which satisfy a given predicate. | 4245 | analogously search for elements which satisfy a given predicate. |
| 4249 | 4246 | ||
| 4250 | @defun tailp sublist list | 4247 | @defun cl-tailp sublist list |
| 4251 | This function returns @code{t} if @var{sublist} is a sublist of | 4248 | This 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 |
| 4253 | any of its @code{cdr}s. | 4250 | any 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} |
| 4257 | This function conses @var{item} onto the front of @var{list}, | 4254 | This function conses @var{item} onto the front of @var{list}, |
| 4258 | like @code{(cons @var{item} @var{list})}, but only if @var{item} | 4255 | like @code{(cons @var{item} @var{list})}, but only if @var{item} |
| 4259 | is not already present on the list (as determined by @code{member*}). | 4256 | is not already present on the list (as determined by @code{cl-member}). |
| 4260 | If a @code{:key} argument is specified, it is applied to | 4257 | If 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 |
| 4262 | the search, on the reasoning that @var{item} is ``about'' to | 4259 | the search, on the reasoning that @var{item} is ``about'' to |
| 4263 | become part of the list. | 4260 | become 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} |
| 4267 | This function combines two lists which represent sets of items, | 4264 | This function combines two lists which represent sets of items, |
| 4268 | returning a list that represents the union of those two sets. | 4265 | returning a list that represents the union of those two sets. |
| 4269 | The result list will contain all items which appear in @var{list1} | 4266 | The 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 | |||
| 4275 | undefined. | 4272 | undefined. |
| 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} |
| 4279 | This is a destructive version of @code{union}; rather than copying, | 4276 | This is a destructive version of @code{cl-union}; rather than copying, |
| 4280 | it tries to reuse the storage of the argument lists if possible. | 4277 | it 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} |
| 4284 | This function computes the intersection of the sets represented | 4281 | This function computes the intersection of the sets represented |
| 4285 | by @var{list1} and @var{list2}. It returns the list of items | 4282 | by @var{list1} and @var{list2}. It returns the list of items |
| 4286 | which appear in both @var{list1} and @var{list2}. | 4283 | which 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} |
| 4290 | This is a destructive version of @code{intersection}. It | 4287 | This is a destructive version of @code{cl-intersection}. It |
| 4291 | tries to reuse storage of @var{list1} rather than copying. | 4288 | tries to reuse storage of @var{list1} rather than copying. |
| 4292 | It does @emph{not} reuse the storage of @var{list2}. | 4289 | It 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} |
| 4296 | This function computes the ``set difference'' of @var{list1} | 4293 | This function computes the ``set difference'' of @var{list1} |
| 4297 | and @var{list2}, i.e., the set of elements that appear in | 4294 | and @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} |
| 4302 | This is a destructive @code{set-difference}, which will try | 4299 | This is a destructive @code{cl-set-difference}, which will try |
| 4303 | to reuse @var{list1} if possible. | 4300 | to 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} |
| 4307 | This function computes the ``set exclusive or'' of @var{list1} | 4304 | This function computes the ``set exclusive or'' of @var{list1} |
| 4308 | and @var{list2}, i.e., the set of elements that appear in | 4305 | and @var{list2}, i.e., the set of elements that appear in |
| 4309 | exactly one of @var{list1} and @var{list2}. | 4306 | exactly 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} |
| 4313 | This is a destructive @code{set-exclusive-or}, which will try | 4310 | This is a destructive @code{cl-set-exclusive-or}, which will try |
| 4314 | to reuse @var{list1} and @var{list2} if possible. | 4311 | to 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} |
| 4318 | This function checks whether @var{list1} represents a subset | 4315 | This function checks whether @var{list1} represents a subset |
| 4319 | of @var{list2}, i.e., whether every element of @var{list1} | 4316 | of @var{list2}, i.e., whether every element of @var{list1} |
| 4320 | also appears in @var{list2}. | 4317 | also appears in @var{list2}. |
| @@ -4328,7 +4325,7 @@ An @dfn{association list} is a list representing a mapping from | |||
| 4328 | one set of values to another; any list whose elements are cons | 4325 | one set of values to another; any list whose elements are cons |
| 4329 | cells is an association list. | 4326 | cells 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} |
| 4332 | This function searches the association list @var{a-list} for an | 4329 | This function searches the association list @var{a-list} for an |
| 4333 | element whose @code{car} matches (in the sense of @code{:test}, | 4330 | element 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 | |||
| 4340 | elements of @var{a-list} to be an error.) | 4337 | elements 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} |
| 4344 | This function searches for an element whose @code{cdr} matches | 4341 | This 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 |
| 4346 | the inverse of the mapping to @var{item}. | 4343 | the 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 |
| 4353 | The @code{assoc-if}, @code{assoc-if-not}, @code{rassoc-if}, | 4350 | The @code{cl-assoc-if}, @code{cl-assoc-if-not}, @code{cl-rassoc-if}, |
| 4354 | and @code{rassoc-if-not} functions are defined similarly. | 4351 | and @code{cl-rassoc-if-not} functions are defined similarly. |
| 4355 | 4352 | ||
| 4356 | Two simple functions for constructing association lists are: | 4353 | Two simple functions for constructing association lists are: |
| 4357 | 4354 | ||
| 4358 | @defun acons key value alist | 4355 | @defun cl-acons key value alist |
| 4359 | This is equivalent to @code{(cons (cons @var{key} @var{value}) @var{alist})}. | 4356 | This 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 |
| 4363 | This is equivalent to @code{(nconc (mapcar* 'cons @var{keys} @var{values}) | 4360 | This 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 | |||
| 4382 | implements structures as vectors (or lists upon request) with a | 4379 | implements structures as vectors (or lists upon request) with a |
| 4383 | special ``tag'' symbol to identify them. | 4380 | special ``tag'' symbol to identify them. |
| 4384 | 4381 | ||
| 4385 | @defspec defstruct name slots@dots{} | 4382 | @defspec cl-defstruct name slots@dots{} |
| 4386 | The @code{defstruct} form defines a new structure type called | 4383 | The @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} |
| 4388 | may begin with a string which documents the structure type.) | 4385 | may begin with a string which documents the structure type.) |
| 4389 | In the simplest case, @var{name} and each of the @var{slots} | 4386 | In the simplest case, @var{name} and each of the @var{slots} |
| 4390 | are symbols. For example, | 4387 | are 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 | |||
| 4401 | using @code{setf} on any of these place forms: | 4398 | using @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 | ||
| 4407 | You can create a new @code{person} by calling @code{make-person}, | 4404 | You 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 | |||
| 4465 | not change afterward. | 4462 | not 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 | ||
| 4474 | Any slot options other than @code{:read-only} are ignored. | 4471 | Any slot options other than @code{:read-only} are ignored. |
| @@ -4480,10 +4477,10 @@ by arguments. (By contrast, slot options are key-value pairs not | |||
| 4480 | enclosed in lists.) | 4477 | enclosed 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 | ||
| 4489 | The following structure options are recognized. | 4486 | The following structure options are recognized. |
| @@ -4529,15 +4526,15 @@ as well unless you disable it with a simple-format @code{:constructor} | |||
| 4529 | option. | 4526 | option. |
| 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 | ||
| 4543 | The first constructor here takes its arguments positionally rather | 4540 | The 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 |
| 4577 | This option implements a very limited form of C++-style inheritance. | 4574 | This option implements a very limited form of C++-style inheritance. |
| 4578 | The argument is the name of another structure type previously | 4575 | The argument is the name of another structure type previously |
| 4579 | created with @code{defstruct}. The effect is to cause the new | 4576 | created with @code{cl-defstruct}. The effect is to cause the new |
| 4580 | structure type to inherit all of the included structure's slots | 4577 | structure 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 |
| 4582 | descriptors). The new structure is considered a ``specialization'' | 4579 | descriptors). The new structure is considered a ``specialization'' |
| @@ -4589,12 +4586,12 @@ slot descriptors for slots in the included structure, possibly with | |||
| 4589 | modified default values. Borrowing an example from Steele: | 4586 | modified 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 | |||
| 4650 | conjunction with @code{:type}. | 4647 | conjunction 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 | ||
| 4672 | Since unnamed structures don't have tags, @code{defstruct} is not | 4669 | Since unnamed structures don't have tags, @code{cl-defstruct} is not |
| 4673 | able to make a useful predicate for recognizing them. Also, | 4670 | able to make a useful predicate for recognizing them. Also, |
| 4674 | accessors like @code{person3-name} will be generated but they | 4671 | accessors like @code{person3-name} will be generated but they |
| 4675 | will not be able to do any type checking. The @code{person3-name} | 4672 | will 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 | ||
| 4694 | Except as noted, the @code{defstruct} facility of this package is | 4691 | Except as noted, the @code{cl-defstruct} facility of this package is |
| 4695 | entirely compatible with that of Common Lisp. | 4692 | entirely 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 | |||
| 4708 | away the following assertions. Because assertions might be optimized | 4705 | away the following assertions. Because assertions might be optimized |
| 4709 | away, it is a bad idea for them to include side-effects. | 4706 | away, 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{}] |
| 4712 | This form verifies that @var{test-form} is true (i.e., evaluates to | 4709 | This form verifies that @var{test-form} is true (i.e., evaluates to |
| 4713 | a non-@code{nil} value). If so, it returns @code{nil}. If the test | 4710 | a non-@code{nil} value). If so, it returns @code{nil}. If the test |
| 4714 | is not satisfied, @code{assert} signals an error. | 4711 | is not satisfied, @code{cl-assert} signals an error. |
| 4715 | 4712 | ||
| 4716 | A default error message will be supplied which includes @var{test-form}. | 4713 | A default error message will be supplied which includes @var{test-form}. |
| 4717 | You can specify a different error message by including a @var{string} | 4714 | You 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 | ||
| 4730 | This usage of @var{show-args} is an extension to Common Lisp. In | 4727 | This 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 | |||
| 4734 | makes no sense to specify @var{places}. | 4731 | makes 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] |
| 4738 | This form verifies that @var{form} evaluates to a value of type | 4735 | This 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} |
| 4740 | signals a @code{wrong-type-argument} error. The default error message | 4737 | signals a @code{wrong-type-argument} error. The default error message |
| 4741 | lists the erroneous value along with @var{type} and @var{form} | 4738 | lists the erroneous value along with @var{type} and @var{form} |
| 4742 | themselves. If @var{string} is specified, it is included in the | 4739 | themselves. If @var{string} is specified, it is included in the |
| 4743 | error message in place of @var{type}. For example: | 4740 | error 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 | ||
| 4758 | The following error-related macro is also defined: | 4755 | The 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{} |
| 4761 | This executes @var{forms} exactly like a @code{progn}, except that | 4759 | This executes @var{forms} exactly like a @code{progn}, except that |
| 4762 | errors are ignored during the @var{forms}. More precisely, if | 4760 | errors 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 |
| 4775 | Many of the advanced features of this package, such as @code{defun*}, | 4773 | Many 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 |
| 4777 | byte-compiled code, these complex notations will be expanded into | 4775 | byte-compiled code, these complex notations will be expanded into |
| 4778 | equivalent Lisp code which is simple and efficient. For example, | 4776 | equivalent Lisp code which is simple and efficient. For example, |
| 4779 | the forms | 4777 | the 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 |
| 4795 | which are the most efficient ways of doing these respective operations | 4793 | which are the most efficient ways of doing these respective operations |
| 4796 | in Lisp. Thus, there is no performance penalty for using the more | 4794 | in Lisp. Thus, there is no performance penalty for using the more |
| 4797 | readable @code{incf} and @code{push} forms in your compiled code. | 4795 | readable @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 |
| 4800 | every time they are executed. For this reason it is strongly | 4798 | every time they are executed. For this reason it is strongly |
| 4801 | recommended that code making heavy use of macros be compiled. | 4799 | recommended 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 |
| 4803 | this manual are macros.) A loop using @code{incf} a hundred times | 4801 | this manual are macros.) A loop using @code{cl-incf} a hundred times |
| 4804 | will execute considerably faster if compiled, and will also | 4802 | will execute considerably faster if compiled, and will also |
| 4805 | garbage-collect less because the macro expansion will not have | 4803 | garbage-collect less because the macro expansion will not have |
| 4806 | to be generated, used, and thrown away a hundred times. | 4804 | to 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; | |||
| 4824 | the expansion | 4822 | the 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 |
| 4837 | will be inserted into the buffer. (The @code{block} macro is | 4835 | will be inserted into the buffer. (The @code{cl-block} macro is |
| 4838 | expanded differently in the interpreter and compiler, so | 4836 | expanded 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 |
| 4840 | variable @code{G1004} was created by @code{gensym}.) | 4838 | variable @code{G1004} was created by @code{cl-gensym}.) |
| 4841 | 4839 | ||
| 4842 | If the optional argument @var{full} is true, then @emph{all} | 4840 | If the optional argument @var{full} is true, then @emph{all} |
| 4843 | macros are expanded, including @code{block}, @code{eval-when}, | 4841 | macros are expanded, including @code{cl-block}, @code{cl-eval-when}, |
| 4844 | and compiler macros. Expansion is done as if @var{form} were | 4842 | and compiler macros. Expansion is done as if @var{form} were |
| 4845 | a top-level form in a file being compiled. For example, | 4843 | a 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 | ||
| 4856 | Note that @code{adjoin}, @code{caddr}, and @code{member*} all | 4854 | Note that @code{cl-adjoin}, @code{cl-caddr}, and @code{cl-member} all |
| 4857 | have built-in compiler macros to optimize them in common cases. | 4855 | have 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 | |||
| 4875 | supposed to arise in complying programs; implementations are strongly | 4873 | supposed to arise in complying programs; implementations are strongly |
| 4876 | encouraged but not required to signal an error in these situations. | 4874 | encouraged but not required to signal an error in these situations. |
| 4877 | This package sometimes omits such error checking in the interest of | 4875 | This package sometimes omits such error checking in the interest of |
| 4878 | compactness and efficiency. For example, @code{do} variable | 4876 | compactness and efficiency. For example, @code{cl-do} variable |
| 4879 | specifiers are supposed to be lists of one, two, or three forms; | 4877 | specifiers are supposed to be lists of one, two, or three forms; |
| 4880 | extra forms are ignored by this package rather than signaling a | 4878 | extra forms are ignored by this package rather than signaling a |
| 4881 | syntax error. The @code{endp} function is simply a synonym for | 4879 | syntax 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 |
| 4883 | will accept an odd number of arguments, treating the trailing | 4881 | will accept an odd number of arguments, treating the trailing |
| 4884 | keyword as if it were followed by the value @code{nil}. | 4882 | keyword as if it were followed by the value @code{nil}. |
| 4885 | 4883 | ||
| 4886 | Argument lists (as processed by @code{defun*} and friends) | 4884 | Argument 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 |
| 4888 | mentioned; in particular, keyword arguments are checked for | 4886 | mentioned; in particular, keyword arguments are checked for |
| 4889 | validity, and @code{&allow-other-keys} and @code{:allow-other-keys} | 4887 | validity, and @code{&allow-other-keys} and @code{:allow-other-keys} |
| 4890 | are fully implemented. Keyword validity checking is slightly | 4888 | are fully implemented. Keyword validity checking is slightly |
| 4891 | time consuming (though not too bad in byte-compiled code); | 4889 | time consuming (though not too bad in byte-compiled code); |
| 4892 | you can use @code{&allow-other-keys} to omit this check. Functions | 4890 | you can use @code{&allow-other-keys} to omit this check. Functions |
| 4893 | defined in this package such as @code{find} and @code{member*} | 4891 | defined in this package such as @code{cl-find} and @code{cl-member} |
| 4894 | do check their keyword arguments for validity. | 4892 | do check their keyword arguments for validity. |
| 4895 | 4893 | ||
| 4896 | @ifinfo | 4894 | @ifinfo |
| @@ -4904,10 +4902,10 @@ do check their keyword arguments for validity. | |||
| 4904 | Use of the optimizing Emacs compiler is highly recommended; many of the Common | 4902 | Use of the optimizing Emacs compiler is highly recommended; many of the Common |
| 4905 | Lisp macros emit | 4903 | Lisp macros emit |
| 4906 | code which can be improved by optimization. In particular, | 4904 | code 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 |
| 4909 | optimizing compiler removes @code{block}s which are not actually | 4907 | optimizing compiler removes @code{cl-block}s which are not actually |
| 4910 | referenced by @code{return} or @code{return-from} inside the block. | 4908 | referenced 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. | |||
| 4916 | Following is a list of all known incompatibilities between this | 4914 | Following is a list of all known incompatibilities between this |
| 4917 | package and Common Lisp as documented in Steele (2nd edition). | 4915 | package and Common Lisp as documented in Steele (2nd edition). |
| 4918 | 4916 | ||
| 4917 | @ignore | ||
| 4919 | Certain function names, such as @code{member}, @code{assoc}, and | 4918 | Certain 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 |
| 4921 | functions; this package appends @samp{*} to the names of its | 4920 | functions; this package appends @samp{*} to the names of its |
| 4922 | Common Lisp versions of these functions. | 4921 | Common Lisp versions of these functions. |
| 4922 | @end ignore | ||
| 4923 | 4923 | ||
| 4924 | The word @code{defun*} is required instead of @code{defun} in order | 4924 | The word @code{cl-defun} is required instead of @code{defun} in order |
| 4925 | to use extended Common Lisp argument lists in a function. Likewise, | 4925 | to 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 |
| 4927 | which understand full-featured argument lists. The @code{&whole} | 4927 | which understand full-featured argument lists. The @code{&whole} |
| 4928 | keyword does not work in @code{defmacro} argument lists (except | 4928 | keyword does not work in @code{defmacro} argument lists (except |
| 4929 | inside recursive argument lists). | 4929 | inside recursive argument lists). |
| 4930 | 4930 | ||
| 4931 | The @code{equal} predicate does not distinguish | 4931 | The @code{equal} predicate does not distinguish |
| 4932 | between IEEE floating-point plus and minus zero. The @code{equalp} | 4932 | between IEEE floating-point plus and minus zero. The @code{cl-equalp} |
| 4933 | predicate has several differences with Common Lisp; @pxref{Predicates}. | 4933 | predicate has several differences with Common Lisp; @pxref{Predicates}. |
| 4934 | 4934 | ||
| 4935 | The @code{setf} mechanism is entirely compatible, except that | 4935 | The @code{setf} mechanism is entirely compatible, except that |
| @@ -4937,21 +4937,21 @@ setf-methods return a list of five values rather than five | |||
| 4937 | values directly. Also, the new ``@code{setf} function'' concept | 4937 | values 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 | ||
| 4940 | The @code{do-all-symbols} form is the same as @code{do-symbols} | 4940 | The @code{cl-do-all-symbols} form is the same as @code{cl-do-symbols} |
| 4941 | with no @var{obarray} argument. In Common Lisp, this form would | 4941 | with no @var{obarray} argument. In Common Lisp, this form would |
| 4942 | iterate over all symbols in all packages. Since Emacs obarrays | 4942 | iterate over all symbols in all packages. Since Emacs obarrays |
| 4943 | are not a first-class package mechanism, there is no way for | 4943 | are 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 | ||
| 4946 | The @code{loop} macro is complete except that @code{loop-finish} | 4946 | The @code{cl-loop} macro is complete except that @code{loop-finish} |
| 4947 | and type specifiers are unimplemented. | 4947 | and type specifiers are unimplemented. |
| 4948 | 4948 | ||
| 4949 | The multiple-value return facility treats lists as multiple | 4949 | The multiple-value return facility treats lists as multiple |
| 4950 | values, since Emacs Lisp cannot support multiple return values | 4950 | values, since Emacs Lisp cannot support multiple return values |
| 4951 | directly. The macros will be compatible with Common Lisp if | 4951 | directly. 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 |
| 4953 | a @code{multiple-value-bind} or other multiple-value receiver; | 4953 | a @code{cl-multiple-value-bind} or other multiple-value receiver; |
| 4954 | if @code{values} is used without @code{multiple-value-@dots{}} | 4954 | if @code{values} is used without @code{cl-multiple-value-@dots{}} |
| 4955 | or vice-versa the effect will be different from Common Lisp. | 4955 | or vice-versa the effect will be different from Common Lisp. |
| 4956 | 4956 | ||
| 4957 | Many Common Lisp declarations are ignored, and others match | 4957 | Many Common Lisp declarations are ignored, and others match |
| @@ -4960,17 +4960,18 @@ example, local @code{special} declarations, which are purely | |||
| 4960 | advisory in Emacs Lisp, do not rigorously obey the scoping rules | 4960 | advisory in Emacs Lisp, do not rigorously obey the scoping rules |
| 4961 | set down in Steele's book. | 4961 | set down in Steele's book. |
| 4962 | 4962 | ||
| 4963 | The variable @code{*gensym-counter*} starts out with a pseudo-random | 4963 | The variable @code{cl--gensym-counter} starts out with a pseudo-random |
| 4964 | value rather than with zero. This is to cope with the fact that | 4964 | value rather than with zero. This is to cope with the fact that |
| 4965 | generated symbols become interned when they are written to and | 4965 | generated symbols become interned when they are written to and |
| 4966 | loaded back from a file. | 4966 | loaded back from a file. |
| 4967 | 4967 | ||
| 4968 | The @code{defstruct} facility is compatible, except that structures | 4968 | The @code{cl-defstruct} facility is compatible, except that structures |
| 4969 | are of type @code{:type vector :named} by default rather than some | 4969 | are of type @code{:type vector :named} by default rather than some |
| 4970 | special, distinct type. Also, the @code{:type} slot option is ignored. | 4970 | special, distinct type. Also, the @code{:type} slot option is ignored. |
| 4971 | 4971 | ||
| 4972 | The second argument of @code{check-type} is treated differently. | 4972 | The 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. | |||
| 4989 | The @code{defkeyword} form and @code{keywordp} function are not | 4990 | The @code{defkeyword} form and @code{keywordp} function are not |
| 4990 | implemented in this package. | 4991 | implemented in this package. |
| 4991 | 4992 | ||
| 4993 | @ignore | ||
| 4992 | The @code{member}, @code{floor}, @code{ceiling}, @code{truncate}, | 4994 | The @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 |
| 4994 | by @samp{*} in this package to avoid collision with existing | 4996 | by @samp{*} in this package to avoid collision with existing |
| @@ -4998,6 +5000,7 @@ causing serious portability problems. (Some more | |||
| 4998 | recent versions of the Quiroz package changed the names to | 5000 | recent 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 |
| 5000 | aliases for @code{member*}, etc.) | 5002 | aliases for @code{member*}, etc.) |
| 5003 | @end ignore | ||
| 5001 | 5004 | ||
| 5002 | Certain functions in the old package which were buggy or inconsistent | 5005 | Certain functions in the old package which were buggy or inconsistent |
| 5003 | with the Common Lisp standard are incompatible with the conforming | 5006 | with 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} | |||
| 5006 | failed to preserve correct order of evaluation of its arguments, etc. | 5009 | failed to preserve correct order of evaluation of its arguments, etc. |
| 5007 | 5010 | ||
| 5008 | Finally, unlike the older package, this package is careful to | 5011 | Finally, unlike the older package, this package is careful to |
| 5009 | prefix all of its internal names with @code{cl-}. Except for a | 5012 | prefix all of its internal names with @code{cl--}. Except for a |
| 5010 | few functions which are explicitly defined as additional features | 5013 | few 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 |
| 5012 | export any non-@samp{cl-} symbols which are not also part of Common | 5015 | export any non-@samp{cl-} symbols which are not also part of Common |
| 5013 | Lisp. | 5016 | Lisp. |
| 5014 | 5017 | ||
| @@ -5267,7 +5270,7 @@ where a more iteratively-minded programmer might write one of | |||
| 5267 | these forms: | 5270 | these 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 | ||