diff options
| author | Glenn Morris | 2012-11-03 12:14:22 -0700 |
|---|---|---|
| committer | Glenn Morris | 2012-11-03 12:14:22 -0700 |
| commit | f58542e1510319921d1745e0ad647ed42b1157f2 (patch) | |
| tree | 7dce084101c1b16c1249eda33e03cbea15d08abc /doc/misc | |
| parent | 7ccfb720b477df05042729e0e300bae5922f5120 (diff) | |
| parent | 92246540b0616afd90600aabbac964f5a0b544ca (diff) | |
| download | emacs-f58542e1510319921d1745e0ad647ed42b1157f2.tar.gz emacs-f58542e1510319921d1745e0ad647ed42b1157f2.zip | |
Merge from emacs-24; up to 2012-11-03T05:11:34Z!dmantipov@yandex.ru
Diffstat (limited to 'doc/misc')
| -rw-r--r-- | doc/misc/ChangeLog | 11 | ||||
| -rw-r--r-- | doc/misc/cl.texi | 358 |
2 files changed, 186 insertions, 183 deletions
diff --git a/doc/misc/ChangeLog b/doc/misc/ChangeLog index 768a846bd1a..0a32fd82044 100644 --- a/doc/misc/ChangeLog +++ b/doc/misc/ChangeLog | |||
| @@ -1,3 +1,14 @@ | |||
| 1 | 2012-11-03 Glenn Morris <rgm@gnu.org> | ||
| 2 | |||
| 3 | * cl.texi: Further general copyedits. | ||
| 4 | (List Functions): Remove copy-tree, standard elisp for some time. | ||
| 5 | (Efficiency Concerns): Comment out examples that no longer apply. | ||
| 6 | (Compiler Optimizations): Rename from "Optimizing Compiler"; reword. | ||
| 7 | (Creating Symbols, Random Numbers): De-emphasize internal | ||
| 8 | variables cl--gensym-counter and cl--random-state. (Bug#12788) | ||
| 9 | (Naming Conventions, Type Predicates, Macros) | ||
| 10 | (Predicates on Numbers): No longer mention cl-floatp-safe. | ||
| 11 | |||
| 1 | 2012-11-02 Katsumi Yamaoka <yamaoka@jpl.org> | 12 | 2012-11-02 Katsumi Yamaoka <yamaoka@jpl.org> |
| 2 | 13 | ||
| 3 | * gnus.texi (Mail Source Specifiers): | 14 | * gnus.texi (Mail Source Specifiers): |
diff --git a/doc/misc/cl.texi b/doc/misc/cl.texi index 4a728049ce8..e182c2600f9 100644 --- a/doc/misc/cl.texi +++ b/doc/misc/cl.texi | |||
| @@ -229,7 +229,7 @@ by @code{cl--}. Here is a complete list of functions prefixed by | |||
| 229 | 229 | ||
| 230 | @example | 230 | @example |
| 231 | cl-callf cl-callf2 cl-defsubst | 231 | cl-callf cl-callf2 cl-defsubst |
| 232 | cl-floatp-safe cl-letf cl-letf* | 232 | cl-letf cl-letf* |
| 233 | @end example | 233 | @end example |
| 234 | 234 | ||
| 235 | @c This is not uninteresting I suppose, but is of zero practical relevance | 235 | @c This is not uninteresting I suppose, but is of zero practical relevance |
| @@ -239,13 +239,13 @@ they do not cause other components like @file{cl-extra} to be loaded. | |||
| 239 | 239 | ||
| 240 | @example | 240 | @example |
| 241 | cl-evenp cl-oddp cl-minusp | 241 | cl-evenp cl-oddp cl-minusp |
| 242 | cl-plusp cl-floatp-safe cl-endp | 242 | cl-plusp cl-endp cl-subst |
| 243 | cl-copy-list cl-list* cl-ldiff | 243 | cl-copy-list cl-list* cl-ldiff |
| 244 | cl-rest cl-decf [1] cl-incf [1] | 244 | cl-rest cl-decf [1] cl-incf [1] |
| 245 | cl-acons cl-adjoin [2] cl-pairlis | 245 | cl-acons cl-adjoin [2] cl-pairlis |
| 246 | cl-pushnew [1,2] cl-declaim cl-proclaim | 246 | cl-pushnew [1,2] cl-declaim cl-proclaim |
| 247 | cl-caaar@dots{}cl-cddddr cl-first@dots{}cl-tenth | 247 | cl-caaar@dots{}cl-cddddr cl-first@dots{}cl-tenth |
| 248 | cl-subst cl-mapcar [3] | 248 | cl-mapcar [3] |
| 249 | @end example | 249 | @end example |
| 250 | 250 | ||
| 251 | @noindent | 251 | @noindent |
| @@ -300,7 +300,8 @@ calls to it may be expanded into in-line code by the byte compiler. | |||
| 300 | This is analogous to the @code{defsubst} form; | 300 | This is analogous to the @code{defsubst} form; |
| 301 | @code{cl-defsubst} uses a different method (compiler macros) which | 301 | @code{cl-defsubst} uses a different method (compiler macros) which |
| 302 | works in all versions of Emacs, and also generates somewhat more | 302 | works in all versions of Emacs, and also generates somewhat more |
| 303 | @c Really? | 303 | @c For some examples, |
| 304 | @c see http://lists.gnu.org/archive/html/emacs-devel/2012-11/msg00009.html | ||
| 304 | efficient inline expansions. In particular, @code{cl-defsubst} | 305 | efficient inline expansions. In particular, @code{cl-defsubst} |
| 305 | arranges for the processing of keyword arguments, default values, | 306 | arranges for the processing of keyword arguments, default values, |
| 306 | etc., to be done at compile-time whenever possible. | 307 | etc., to be done at compile-time whenever possible. |
| @@ -702,11 +703,13 @@ The type symbol @code{real} is a synonym for @code{number}, and | |||
| 702 | The type symbols @code{character} and @code{string-char} match | 703 | The type symbols @code{character} and @code{string-char} match |
| 703 | integers in the range from 0 to 255. | 704 | integers in the range from 0 to 255. |
| 704 | 705 | ||
| 706 | @c No longer relevant, so covered by first item above (float -> floatp). | ||
| 707 | @ignore | ||
| 705 | @item | 708 | @item |
| 706 | The type symbol @code{float} uses the @code{cl-floatp-safe} predicate | 709 | The type symbol @code{float} uses the @code{cl-floatp-safe} predicate |
| 707 | defined by this package rather than @code{floatp}, so it will work | 710 | defined by this package rather than @code{floatp}, so it will work |
| 708 | @c FIXME are any such platforms still relevant? | ||
| 709 | correctly even in Emacs versions without floating-point support. | 711 | correctly even in Emacs versions without floating-point support. |
| 712 | @end ignore | ||
| 710 | 713 | ||
| 711 | @item | 714 | @item |
| 712 | The type list @code{(integer @var{low} @var{high})} represents all | 715 | The type list @code{(integer @var{low} @var{high})} represents all |
| @@ -833,7 +836,7 @@ constructs. | |||
| 833 | * Conditionals:: @code{cl-case}, @code{cl-typecase}. | 836 | * Conditionals:: @code{cl-case}, @code{cl-typecase}. |
| 834 | * Blocks and Exits:: @code{cl-block}, @code{cl-return}, @code{cl-return-from}. | 837 | * Blocks and Exits:: @code{cl-block}, @code{cl-return}, @code{cl-return-from}. |
| 835 | * Iteration:: @code{cl-do}, @code{cl-dotimes}, @code{cl-dolist}, @code{cl-do-symbols}. | 838 | * Iteration:: @code{cl-do}, @code{cl-dotimes}, @code{cl-dolist}, @code{cl-do-symbols}. |
| 836 | * Loop Facility:: The Common Lisp @code{cl-loop} macro. | 839 | * Loop Facility:: The Common Lisp @code{loop} macro. |
| 837 | * Multiple Values:: @code{cl-values}, @code{cl-multiple-value-bind}, etc. | 840 | * Multiple Values:: @code{cl-values}, @code{cl-multiple-value-bind}, etc. |
| 838 | @end menu | 841 | @end menu |
| 839 | 842 | ||
| @@ -1521,7 +1524,7 @@ Common Lisp @dfn{blocks} provide a non-local exit mechanism very | |||
| 1521 | similar to @code{catch} and @code{throw}, with lexical scoping. | 1524 | similar to @code{catch} and @code{throw}, with lexical scoping. |
| 1522 | This package actually implements @code{cl-block} | 1525 | This package actually implements @code{cl-block} |
| 1523 | in terms of @code{catch}; however, the lexical scoping allows the | 1526 | in terms of @code{catch}; however, the lexical scoping allows the |
| 1524 | optimizing byte-compiler to omit the costly @code{catch} step if the | 1527 | byte-compiler to omit the costly @code{catch} step if the |
| 1525 | body of the block does not actually @code{cl-return-from} the block. | 1528 | body of the block does not actually @code{cl-return-from} the block. |
| 1526 | 1529 | ||
| 1527 | @defmac cl-block name forms@dots{} | 1530 | @defmac cl-block name forms@dots{} |
| @@ -1558,7 +1561,7 @@ just as in Common Lisp. | |||
| 1558 | Because they are implemented in terms of Emacs Lisp's @code{catch} | 1561 | Because they are implemented in terms of Emacs Lisp's @code{catch} |
| 1559 | and @code{throw}, blocks have the same overhead as actual | 1562 | and @code{throw}, blocks have the same overhead as actual |
| 1560 | @code{catch} constructs (roughly two function calls). However, | 1563 | @code{catch} constructs (roughly two function calls). However, |
| 1561 | the optimizing byte compiler will optimize away the @code{catch} | 1564 | the byte compiler will optimize away the @code{catch} |
| 1562 | if the block does | 1565 | if the block does |
| 1563 | not in fact contain any @code{cl-return} or @code{cl-return-from} calls | 1566 | not in fact contain any @code{cl-return} or @code{cl-return-from} calls |
| 1564 | that jump to it. This means that @code{cl-do} loops and @code{cl-defun} | 1567 | that jump to it. This means that @code{cl-do} loops and @code{cl-defun} |
| @@ -1723,18 +1726,18 @@ iterating over vectors or lists. | |||
| 1723 | @section Loop Facility | 1726 | @section Loop Facility |
| 1724 | 1727 | ||
| 1725 | @noindent | 1728 | @noindent |
| 1726 | A common complaint with Lisp's traditional looping constructs is | 1729 | A common complaint with Lisp's traditional looping constructs was |
| 1727 | that they are either too simple and limited, such as Common Lisp's | 1730 | that they were either too simple and limited, such as @code{dotimes} |
| 1728 | @code{dotimes} or Emacs Lisp's @code{while}, or too unreadable and | 1731 | or @code{while}, or too unreadable and obscure, like Common Lisp's |
| 1729 | obscure, like Common Lisp's @code{do} loop. | 1732 | @code{do} loop. |
| 1730 | 1733 | ||
| 1731 | To remedy this, recent versions of Common Lisp have added a new | 1734 | To remedy this, Common Lisp added a construct called the ``Loop |
| 1732 | construct called the ``Loop Facility'' or ``@code{loop} macro'', | 1735 | Facility'' or ``@code{loop} macro'', with an easy-to-use but very |
| 1733 | with an easy-to-use but very powerful and expressive syntax. | 1736 | powerful and expressive syntax. |
| 1734 | 1737 | ||
| 1735 | @menu | 1738 | @menu |
| 1736 | * Loop Basics:: @code{cl-loop} macro, basic clause structure. | 1739 | * Loop Basics:: The @code{cl-loop} macro, basic clause structure. |
| 1737 | * Loop Examples:: Working examples of @code{cl-loop} macro. | 1740 | * Loop Examples:: Working examples of the @code{cl-loop} macro. |
| 1738 | * For Clauses:: Clauses introduced by @code{for} or @code{as}. | 1741 | * For Clauses:: Clauses introduced by @code{for} or @code{as}. |
| 1739 | * Iteration Clauses:: @code{repeat}, @code{while}, @code{thereis}, etc. | 1742 | * Iteration Clauses:: @code{repeat}, @code{while}, @code{thereis}, etc. |
| 1740 | * Accumulation Clauses:: @code{collect}, @code{sum}, @code{maximize}, etc. | 1743 | * Accumulation Clauses:: @code{collect}, @code{sum}, @code{maximize}, etc. |
| @@ -1767,9 +1770,9 @@ Common Lisp specifies a certain general order of clauses in a | |||
| 1767 | loop: | 1770 | loop: |
| 1768 | 1771 | ||
| 1769 | @example | 1772 | @example |
| 1770 | (cl-loop @var{name-clause} | 1773 | (loop @var{name-clause} |
| 1771 | @var{var-clauses}@dots{} | 1774 | @var{var-clauses}@dots{} |
| 1772 | @var{action-clauses}@dots{}) | 1775 | @var{action-clauses}@dots{}) |
| 1773 | @end example | 1776 | @end example |
| 1774 | 1777 | ||
| 1775 | The @var{name-clause} optionally gives a name to the implicit | 1778 | The @var{name-clause} optionally gives a name to the implicit |
| @@ -1795,10 +1798,10 @@ also use regular Lisp @code{cl-return} or @code{cl-return-from} to | |||
| 1795 | break out of the loop.) | 1798 | break out of the loop.) |
| 1796 | @end defmac | 1799 | @end defmac |
| 1797 | 1800 | ||
| 1798 | The following sections give some examples of the Loop Macro in | 1801 | The following sections give some examples of the loop macro in |
| 1799 | action, and describe the particular loop clauses in great detail. | 1802 | action, and describe the particular loop clauses in great detail. |
| 1800 | Consult the second edition of Steele for additional discussion | 1803 | Consult the second edition of Steele for additional discussion |
| 1801 | and examples of the @code{loop} macro. | 1804 | and examples. |
| 1802 | 1805 | ||
| 1803 | @node Loop Examples | 1806 | @node Loop Examples |
| 1804 | @subsection Loop Examples | 1807 | @subsection Loop Examples |
| @@ -2162,8 +2165,9 @@ that was just set by the previous clause; in the second loop, | |||
| 2162 | based on the value of @code{x} left over from the previous time | 2165 | based on the value of @code{x} left over from the previous time |
| 2163 | through the loop. | 2166 | through the loop. |
| 2164 | 2167 | ||
| 2165 | Another feature of the @code{cl-loop} macro is @dfn{destructuring}, | 2168 | Another feature of the @code{cl-loop} macro is @emph{destructuring}, |
| 2166 | similar in concept to the destructuring provided by @code{defmacro}. | 2169 | similar in concept to the destructuring provided by @code{defmacro} |
| 2170 | (@pxref{Argument Lists}). | ||
| 2167 | The @var{var} part of any @code{for} clause can be given as a list | 2171 | The @var{var} part of any @code{for} clause can be given as a list |
| 2168 | of variables instead of a single variable. The values produced | 2172 | of variables instead of a single variable. The values produced |
| 2169 | during loop execution must be lists; the values in the lists are | 2173 | during loop execution must be lists; the values in the lists are |
| @@ -2375,7 +2379,7 @@ by the name @code{it} in the ``then'' part. For example: | |||
| 2375 | (setq funny-numbers '(6 13 -1)) | 2379 | (setq funny-numbers '(6 13 -1)) |
| 2376 | @result{} (6 13 -1) | 2380 | @result{} (6 13 -1) |
| 2377 | (cl-loop for x below 10 | 2381 | (cl-loop for x below 10 |
| 2378 | if (oddp x) | 2382 | if (cl-oddp x) |
| 2379 | collect x into odds | 2383 | collect x into odds |
| 2380 | and if (memq x funny-numbers) return (cdr it) end | 2384 | and if (memq x funny-numbers) return (cdr it) end |
| 2381 | else | 2385 | else |
| @@ -2441,15 +2445,14 @@ loop. Many of the examples in this section illustrate the use of | |||
| 2441 | 2445 | ||
| 2442 | @item return @var{form} | 2446 | @item return @var{form} |
| 2443 | This clause causes the loop to return immediately. The following | 2447 | This clause causes the loop to return immediately. The following |
| 2444 | Lisp form is evaluated to give the return value of the @code{loop} | 2448 | Lisp form is evaluated to give the return value of the loop |
| 2445 | form. The @code{finally} clauses, if any, are not executed. | 2449 | form. The @code{finally} clauses, if any, are not executed. |
| 2446 | Of course, @code{return} is generally used inside an @code{if} or | 2450 | Of course, @code{return} is generally used inside an @code{if} or |
| 2447 | @code{unless}, as its use in a top-level loop clause would mean | 2451 | @code{unless}, as its use in a top-level loop clause would mean |
| 2448 | the loop would never get to ``loop'' more than once. | 2452 | the loop would never get to ``loop'' more than once. |
| 2449 | 2453 | ||
| 2450 | The clause @samp{return @var{form}} is equivalent to | 2454 | The clause @samp{return @var{form}} is equivalent to |
| 2451 | @c FIXME cl-do, cl-return? | 2455 | @samp{do (cl-return @var{form})} (or @code{cl-return-from} if the loop |
| 2452 | @samp{do (return @var{form})} (or @code{return-from} if the loop | ||
| 2453 | was named). The @code{return} clause is implemented a bit more | 2456 | was named). The @code{return} clause is implemented a bit more |
| 2454 | efficiently, though. | 2457 | efficiently, though. |
| 2455 | @end table | 2458 | @end table |
| @@ -2463,7 +2466,7 @@ clause, respectively. Consult the source code in file | |||
| 2463 | 2466 | ||
| 2464 | This package's @code{cl-loop} macro is compatible with that of Common | 2467 | This package's @code{cl-loop} macro is compatible with that of Common |
| 2465 | Lisp, except that a few features are not implemented: @code{loop-finish} | 2468 | Lisp, except that a few features are not implemented: @code{loop-finish} |
| 2466 | and data-type specifiers. Naturally, the @code{for} clauses which | 2469 | and data-type specifiers. Naturally, the @code{for} clauses that |
| 2467 | iterate over keymaps, overlays, intervals, frames, windows, and | 2470 | iterate over keymaps, overlays, intervals, frames, windows, and |
| 2468 | buffers are Emacs-specific extensions. | 2471 | buffers are Emacs-specific extensions. |
| 2469 | 2472 | ||
| @@ -2516,17 +2519,17 @@ Destructuring is made available to the user by way of the | |||
| 2516 | following macro: | 2519 | following macro: |
| 2517 | 2520 | ||
| 2518 | @defmac cl-destructuring-bind arglist expr forms@dots{} | 2521 | @defmac cl-destructuring-bind arglist expr forms@dots{} |
| 2519 | This macro expands to code which executes @var{forms}, with | 2522 | This macro expands to code that executes @var{forms}, with |
| 2520 | the variables in @var{arglist} bound to the list of values | 2523 | the variables in @var{arglist} bound to the list of values |
| 2521 | returned by @var{expr}. The @var{arglist} can include all | 2524 | returned by @var{expr}. The @var{arglist} can include all |
| 2522 | the features allowed for @code{defmacro} argument lists, | 2525 | the features allowed for @code{cl-defmacro} argument lists, |
| 2523 | including destructuring. (The @code{&environment} keyword | 2526 | including destructuring. (The @code{&environment} keyword |
| 2524 | is not allowed.) The macro expansion will signal an error | 2527 | is not allowed.) The macro expansion will signal an error |
| 2525 | if @var{expr} returns a list of the wrong number of arguments | 2528 | if @var{expr} returns a list of the wrong number of arguments |
| 2526 | or with incorrect keyword arguments. | 2529 | or with incorrect keyword arguments. |
| 2527 | @end defmac | 2530 | @end defmac |
| 2528 | 2531 | ||
| 2529 | This package also includes the Common Lisp @code{cl-define-compiler-macro} | 2532 | This package also includes the Common Lisp @code{define-compiler-macro} |
| 2530 | facility, which allows you to define compile-time expansions and | 2533 | facility, which allows you to define compile-time expansions and |
| 2531 | optimizations for your functions. | 2534 | optimizations for your functions. |
| 2532 | 2535 | ||
| @@ -2551,7 +2554,7 @@ appears as a standard part of this package: | |||
| 2551 | (cl-define-compiler-macro cl-member (&whole form a list &rest keys) | 2554 | (cl-define-compiler-macro cl-member (&whole form a list &rest keys) |
| 2552 | (if (and (null keys) | 2555 | (if (and (null keys) |
| 2553 | (eq (car-safe a) 'quote) | 2556 | (eq (car-safe a) 'quote) |
| 2554 | (not (floatp-safe (cadr a)))) | 2557 | (not (floatp (cadr a)))) |
| 2555 | (list 'memq a list) | 2558 | (list 'memq a list) |
| 2556 | form)) | 2559 | form)) |
| 2557 | @end example | 2560 | @end example |
| @@ -2589,16 +2592,19 @@ mechanism that allows you to give the compiler special hints | |||
| 2589 | about the types of data that will be stored in particular variables, | 2592 | about the types of data that will be stored in particular variables, |
| 2590 | and about the ways those variables and functions will be used. This | 2593 | and about the ways those variables and functions will be used. This |
| 2591 | package defines versions of all the Common Lisp declaration forms: | 2594 | package defines versions of all the Common Lisp declaration forms: |
| 2592 | @code{cl-declare}, @code{cl-locally}, @code{cl-proclaim}, @code{cl-declaim}, | 2595 | @code{declare}, @code{locally}, @code{proclaim}, @code{declaim}, |
| 2593 | and @code{cl-the}. | 2596 | and @code{the}. |
| 2594 | 2597 | ||
| 2595 | Most of the Common Lisp declarations are not currently useful in | 2598 | Most of the Common Lisp declarations are not currently useful in Emacs |
| 2596 | Emacs Lisp, as the byte-code system provides little opportunity | 2599 | Lisp. For example, the byte-code system provides little |
| 2597 | to benefit from type information, and @code{special} declarations | 2600 | opportunity to benefit from type information. |
| 2598 | are redundant in a fully dynamically-scoped Lisp. A few | 2601 | @ignore |
| 2599 | declarations are meaningful when the optimizing byte | 2602 | and @code{special} declarations are redundant in a fully |
| 2600 | compiler is being used, however. Under the earlier non-optimizing | 2603 | dynamically-scoped Lisp. |
| 2601 | compiler, these declarations will effectively be ignored. | 2604 | @end ignore |
| 2605 | A few declarations are meaningful when byte compiler optimizations | ||
| 2606 | are enabled, as they are by the default. Otherwise these | ||
| 2607 | declarations will effectively be ignored. | ||
| 2602 | 2608 | ||
| 2603 | @defun cl-proclaim decl-spec | 2609 | @defun cl-proclaim decl-spec |
| 2604 | This function records a ``global'' declaration specified by | 2610 | This function records a ``global'' declaration specified by |
| @@ -2609,7 +2615,7 @@ is evaluated and thus should normally be quoted. | |||
| 2609 | @defmac cl-declaim decl-specs@dots{} | 2615 | @defmac cl-declaim decl-specs@dots{} |
| 2610 | This macro is like @code{cl-proclaim}, except that it takes any number | 2616 | This macro is like @code{cl-proclaim}, except that it takes any number |
| 2611 | of @var{decl-spec} arguments, and the arguments are unevaluated and | 2617 | of @var{decl-spec} arguments, and the arguments are unevaluated and |
| 2612 | unquoted. The @code{cl-declaim} macro also puts an @code{(cl-eval-when | 2618 | unquoted. The @code{cl-declaim} macro also puts @code{(cl-eval-when |
| 2613 | (compile load eval) @dots{})} around the declarations so that they will | 2619 | (compile load eval) @dots{})} around the declarations so that they will |
| 2614 | be registered at compile-time as well as at run-time. (This is vital, | 2620 | be registered at compile-time as well as at run-time. (This is vital, |
| 2615 | since normally the declarations are meant to influence the way the | 2621 | since normally the declarations are meant to influence the way the |
| @@ -2632,9 +2638,9 @@ In this package, @code{cl-locally} is no different from @code{progn}. | |||
| 2632 | 2638 | ||
| 2633 | @defmac cl-the type form | 2639 | @defmac cl-the type form |
| 2634 | Type information provided by @code{cl-the} is ignored in this package; | 2640 | Type information provided by @code{cl-the} is ignored in this package; |
| 2635 | in other words, @code{(cl-the @var{type} @var{form})} is equivalent | 2641 | in other words, @code{(cl-the @var{type} @var{form})} is equivalent to |
| 2636 | to @var{form}. Future versions of the optimizing byte-compiler may | 2642 | @var{form}. Future byte-compiler optimizations may make use of this |
| 2637 | make use of this information. | 2643 | information. |
| 2638 | 2644 | ||
| 2639 | For example, @code{mapcar} can map over both lists and arrays. It is | 2645 | For example, @code{mapcar} can map over both lists and arrays. It is |
| 2640 | hard for the compiler to expand @code{mapcar} into an in-line loop | 2646 | hard for the compiler to expand @code{mapcar} into an in-line loop |
| @@ -2655,35 +2661,31 @@ such as @code{type} and @code{ftype}, are silently ignored. | |||
| 2655 | 2661 | ||
| 2656 | @table @code | 2662 | @table @code |
| 2657 | @item special | 2663 | @item special |
| 2664 | @c FIXME ? | ||
| 2658 | Since all variables in Emacs Lisp are ``special'' (in the Common | 2665 | Since all variables in Emacs Lisp are ``special'' (in the Common |
| 2659 | Lisp sense), @code{special} declarations are only advisory. They | 2666 | Lisp sense), @code{special} declarations are only advisory. They |
| 2660 | simply tell the optimizing byte compiler that the specified | 2667 | simply tell the byte compiler that the specified |
| 2661 | variables are intentionally being referred to without being | 2668 | variables are intentionally being referred to without being |
| 2662 | bound in the body of the function. The compiler normally emits | 2669 | bound in the body of the function. The compiler normally emits |
| 2663 | warnings for such references, since they could be typographical | 2670 | warnings for such references, since they could be typographical |
| 2664 | errors for references to local variables. | 2671 | errors for references to local variables. |
| 2665 | 2672 | ||
| 2666 | The declaration @code{(cl-declare (special @var{var1} @var{var2}))} is | 2673 | The declaration @code{(cl-declare (special @var{var1} @var{var2}))} is |
| 2667 | equivalent to @code{(defvar @var{var1}) (defvar @var{var2})} in the | 2674 | equivalent to @code{(defvar @var{var1}) (defvar @var{var2})}. |
| 2668 | optimizing compiler, or to nothing at all in older compilers (which | ||
| 2669 | do not warn for non-local references). | ||
| 2670 | 2675 | ||
| 2671 | In top-level contexts, it is generally better to write | 2676 | In top-level contexts, it is generally better to write |
| 2672 | @code{(defvar @var{var})} than @code{(cl-declaim (special @var{var}))}, | 2677 | @code{(defvar @var{var})} than @code{(cl-declaim (special @var{var}))}, |
| 2673 | since @code{defvar} makes your intentions clearer. But the older | 2678 | since @code{defvar} makes your intentions clearer. |
| 2674 | byte compilers can not handle @code{defvar}s appearing inside of | ||
| 2675 | functions, while @code{(cl-declare (special @var{var}))} takes care | ||
| 2676 | to work correctly with all compilers. | ||
| 2677 | 2679 | ||
| 2678 | @item inline | 2680 | @item inline |
| 2679 | The @code{inline} @var{decl-spec} lists one or more functions | 2681 | The @code{inline} @var{decl-spec} lists one or more functions |
| 2680 | whose bodies should be expanded ``in-line'' into calling functions | 2682 | whose bodies should be expanded ``in-line'' into calling functions |
| 2681 | whenever the compiler is able to arrange for it. For example, | 2683 | whenever the compiler is able to arrange for it. For example, |
| 2682 | the Common Lisp function @code{cadr} is declared @code{inline} | 2684 | the function @code{cl-acons} is declared @code{inline} |
| 2683 | by this package so that the form @code{(cadr @var{x})} will | 2685 | by this package so that the form @code{(cl-acons @var{key} @var{value} |
| 2684 | expand directly into @code{(car (cdr @var{x}))} when it is called | 2686 | @var{alist})} will |
| 2685 | in user functions, for a savings of one (relatively expensive) | 2687 | expand directly into @code{(cons (cons @var{key} @var{value}) @var{alist})} |
| 2686 | function call. | 2688 | when it is called in user functions, so as to save function calls. |
| 2687 | 2689 | ||
| 2688 | The following declarations are all equivalent. Note that the | 2690 | The following declarations are all equivalent. Note that the |
| 2689 | @code{defsubst} form is a convenient way to define a function | 2691 | @code{defsubst} form is a convenient way to define a function |
| @@ -2702,7 +2704,7 @@ request that a function you have defined should be inlined, | |||
| 2702 | but it is impolite to use it to request inlining of an external | 2704 | but it is impolite to use it to request inlining of an external |
| 2703 | function. | 2705 | function. |
| 2704 | 2706 | ||
| 2705 | In Common Lisp, it is possible to use @code{(cl-declare (inline @dots{}))} | 2707 | In Common Lisp, it is possible to use @code{(declare (inline @dots{}))} |
| 2706 | before a particular call to a function to cause just that call to | 2708 | before a particular call to a function to cause just that call to |
| 2707 | be inlined; the current byte compilers provide no way to implement | 2709 | be inlined; the current byte compilers provide no way to implement |
| 2708 | this, so @code{(cl-declare (inline @dots{}))} is currently ignored by | 2710 | this, so @code{(cl-declare (inline @dots{}))} is currently ignored by |
| @@ -2715,8 +2717,7 @@ declaration. | |||
| 2715 | 2717 | ||
| 2716 | @item optimize | 2718 | @item optimize |
| 2717 | This declaration controls how much optimization is performed by | 2719 | This declaration controls how much optimization is performed by |
| 2718 | the compiler. Naturally, it is ignored by the earlier non-optimizing | 2720 | the compiler. |
| 2719 | compilers. | ||
| 2720 | 2721 | ||
| 2721 | The word @code{optimize} is followed by any number of lists like | 2722 | The word @code{optimize} is followed by any number of lists like |
| 2722 | @code{(speed 3)} or @code{(safety 2)}. Common Lisp defines several | 2723 | @code{(speed 3)} or @code{(safety 2)}. Common Lisp defines several |
| @@ -2725,8 +2726,7 @@ and @code{safety}. The value of a quality should be an integer from | |||
| 2725 | 0 to 3, with 0 meaning ``unimportant'' and 3 meaning ``very important''. | 2726 | 0 to 3, with 0 meaning ``unimportant'' and 3 meaning ``very important''. |
| 2726 | The default level for both qualities is 1. | 2727 | The default level for both qualities is 1. |
| 2727 | 2728 | ||
| 2728 | In this package, with the optimizing compiler, the | 2729 | In this package, the @code{speed} quality is tied to the @code{byte-optimize} |
| 2729 | @code{speed} quality is tied to the @code{byte-optimize} | ||
| 2730 | flag, which is set to @code{nil} for @code{(speed 0)} and to | 2730 | flag, which is set to @code{nil} for @code{(speed 0)} and to |
| 2731 | @code{t} for higher settings; and the @code{safety} quality is | 2731 | @code{t} for higher settings; and the @code{safety} quality is |
| 2732 | tied to the @code{byte-compile-delete-errors} flag, which is | 2732 | tied to the @code{byte-compile-delete-errors} flag, which is |
| @@ -2745,22 +2745,22 @@ just because of an error in a fully-optimized Lisp program. | |||
| 2745 | 2745 | ||
| 2746 | The @code{optimize} declaration is normally used in a top-level | 2746 | The @code{optimize} declaration is normally used in a top-level |
| 2747 | @code{cl-proclaim} or @code{cl-declaim} in a file; Common Lisp allows | 2747 | @code{cl-proclaim} or @code{cl-declaim} in a file; Common Lisp allows |
| 2748 | it to be used with @code{cl-declare} to set the level of optimization | 2748 | it to be used with @code{declare} to set the level of optimization |
| 2749 | locally for a given form, but this will not work correctly with the | 2749 | locally for a given form, but this will not work correctly with the |
| 2750 | current version of the optimizing compiler. (The @code{cl-declare} | 2750 | current byte-compiler. (The @code{cl-declare} |
| 2751 | will set the new optimization level, but that level will not | 2751 | will set the new optimization level, but that level will not |
| 2752 | automatically be unset after the enclosing form is done.) | 2752 | automatically be unset after the enclosing form is done.) |
| 2753 | 2753 | ||
| 2754 | @item warn | 2754 | @item warn |
| 2755 | This declaration controls what sorts of warnings are generated | 2755 | This declaration controls what sorts of warnings are generated |
| 2756 | by the byte compiler. Again, only the optimizing compiler | 2756 | by the byte compiler. The word @code{warn} is followed by any |
| 2757 | generates warnings. The word @code{warn} is followed by any | ||
| 2758 | number of ``warning qualities'', similar in form to optimization | 2757 | number of ``warning qualities'', similar in form to optimization |
| 2759 | qualities. The currently supported warning types are | 2758 | qualities. The currently supported warning types are |
| 2760 | @code{redefine}, @code{callargs}, @code{unresolved}, and | 2759 | @code{redefine}, @code{callargs}, @code{unresolved}, and |
| 2761 | @code{free-vars}; in the current system, a value of 0 will | 2760 | @code{free-vars}; in the current system, a value of 0 will |
| 2762 | disable these warnings and any higher value will enable them. | 2761 | disable these warnings and any higher value will enable them. |
| 2763 | See the documentation for the optimizing byte compiler for details. | 2762 | See the documentation of the variable @code{byte-compile-warnings} |
| 2763 | for more details. | ||
| 2764 | @end table | 2764 | @end table |
| 2765 | 2765 | ||
| 2766 | @node Symbols | 2766 | @node Symbols |
| @@ -2867,25 +2867,24 @@ temporary variables. | |||
| 2867 | This function creates a new, uninterned symbol (using @code{make-symbol}) | 2867 | This function creates a new, uninterned symbol (using @code{make-symbol}) |
| 2868 | with a unique name. (The name of an uninterned symbol is relevant | 2868 | with a unique name. (The name of an uninterned symbol is relevant |
| 2869 | only if the symbol is printed.) By default, the name is generated | 2869 | only if the symbol is printed.) By default, the name is generated |
| 2870 | @c FIXME no longer true? | ||
| 2870 | from an increasing sequence of numbers, @samp{G1000}, @samp{G1001}, | 2871 | from an increasing sequence of numbers, @samp{G1000}, @samp{G1001}, |
| 2871 | @samp{G1002}, etc. If the optional argument @var{x} is a string, that | 2872 | @samp{G1002}, etc. If the optional argument @var{x} is a string, that |
| 2872 | string is used as a prefix instead of @samp{G}. Uninterned symbols | 2873 | string is used as a prefix instead of @samp{G}. Uninterned symbols |
| 2873 | are used in macro expansions for temporary variables, to ensure that | 2874 | are used in macro expansions for temporary variables, to ensure that |
| 2874 | their names will not conflict with ``real'' variables in the user's | 2875 | their names will not conflict with ``real'' variables in the user's |
| 2875 | code. | 2876 | code. |
| 2876 | @end defun | ||
| 2877 | 2877 | ||
| 2878 | @defvar cl--gensym-counter | 2878 | (Internally, the variable @code{cl--gensym-counter} holds the counter |
| 2879 | This variable holds the counter used to generate @code{cl-gensym} names. | 2879 | used to generate names. It is incremented after each use. In Common |
| 2880 | It is incremented after each use by @code{cl-gensym}. In Common Lisp | 2880 | Lisp this is initialized with 0, but this package initializes it with |
| 2881 | this is initialized with 0, but this package initializes it with a | 2881 | a random time-dependent value to avoid trouble when two files that |
| 2882 | random (time-dependent) value to avoid trouble when two files that | ||
| 2883 | each used @code{cl-gensym} in their compilation are loaded together. | 2882 | each used @code{cl-gensym} in their compilation are loaded together. |
| 2884 | (Uninterned symbols become interned when the compiler writes them | 2883 | Uninterned symbols become interned when the compiler writes them out |
| 2885 | out to a file and the Emacs loader loads them, so their names have to | 2884 | to a file and the Emacs loader loads them, so their names have to be |
| 2886 | be treated a bit more carefully than in Common Lisp where uninterned | 2885 | treated a bit more carefully than in Common Lisp where uninterned |
| 2887 | symbols remain uninterned after loading.) | 2886 | symbols remain uninterned after loading.) |
| 2888 | @end defvar | 2887 | @end defun |
| 2889 | 2888 | ||
| 2890 | @defun cl-gentemp &optional x | 2889 | @defun cl-gentemp &optional x |
| 2891 | This function is like @code{cl-gensym}, except that it produces a new | 2890 | This function is like @code{cl-gensym}, except that it produces a new |
| @@ -2905,13 +2904,13 @@ provided. | |||
| 2905 | 2904 | ||
| 2906 | @noindent | 2905 | @noindent |
| 2907 | This section defines a few simple Common Lisp operations on numbers | 2906 | This section defines a few simple Common Lisp operations on numbers |
| 2908 | which were left out of Emacs Lisp. | 2907 | that were left out of Emacs Lisp. |
| 2909 | 2908 | ||
| 2910 | @menu | 2909 | @menu |
| 2911 | * Predicates on Numbers:: @code{cl-plusp}, @code{cl-oddp}, @code{cl-floatp-safe}, etc. | 2910 | * Predicates on Numbers:: @code{cl-plusp}, @code{cl-oddp}, etc. |
| 2912 | * Numerical Functions:: @code{abs}, @code{cl-floor}, etc. | 2911 | * Numerical Functions:: @code{cl-floor}, @code{cl-ceiling}, etc. |
| 2913 | * Random Numbers:: @code{cl-random}, @code{cl-make-random-state}. | 2912 | * Random Numbers:: @code{cl-random}, @code{cl-make-random-state}. |
| 2914 | * Implementation Parameters:: @code{cl-most-positive-float}. | 2913 | * Implementation Parameters:: @code{cl-most-positive-float}, etc. |
| 2915 | @end menu | 2914 | @end menu |
| 2916 | 2915 | ||
| 2917 | @node Predicates on Numbers | 2916 | @node Predicates on Numbers |
| @@ -2941,11 +2940,13 @@ This predicate tests whether @var{integer} is even. It is an | |||
| 2941 | error if the argument is not an integer. | 2940 | error if the argument is not an integer. |
| 2942 | @end defun | 2941 | @end defun |
| 2943 | 2942 | ||
| 2943 | @ignore | ||
| 2944 | @defun cl-floatp-safe object | 2944 | @defun cl-floatp-safe object |
| 2945 | This predicate tests whether @var{object} is a floating-point | 2945 | This predicate tests whether @var{object} is a floating-point |
| 2946 | number. On systems that support floating-point, this is equivalent | 2946 | number. On systems that support floating-point, this is equivalent |
| 2947 | to @code{floatp}. On other systems, this always returns @code{nil}. | 2947 | to @code{floatp}. On other systems, this always returns @code{nil}. |
| 2948 | @end defun | 2948 | @end defun |
| 2949 | @end ignore | ||
| 2949 | 2950 | ||
| 2950 | @node Numerical Functions | 2951 | @node Numerical Functions |
| 2951 | @section Numerical Functions | 2952 | @section Numerical Functions |
| @@ -3036,6 +3037,7 @@ of @code{cl-truncate}. | |||
| 3036 | This package also provides an implementation of the Common Lisp | 3037 | This package also provides an implementation of the Common Lisp |
| 3037 | random number generator. It uses its own additive-congruential | 3038 | random number generator. It uses its own additive-congruential |
| 3038 | algorithm, which is much more likely to give statistically clean | 3039 | algorithm, which is much more likely to give statistically clean |
| 3040 | @c FIXME? Still true? | ||
| 3039 | random numbers than the simple generators supplied by many | 3041 | random numbers than the simple generators supplied by many |
| 3040 | operating systems. | 3042 | operating systems. |
| 3041 | 3043 | ||
| @@ -3043,22 +3045,16 @@ operating systems. | |||
| 3043 | This function returns a random nonnegative number less than | 3045 | This function returns a random nonnegative number less than |
| 3044 | @var{number}, and of the same type (either integer or floating-point). | 3046 | @var{number}, and of the same type (either integer or floating-point). |
| 3045 | The @var{state} argument should be a @code{random-state} object | 3047 | The @var{state} argument should be a @code{random-state} object |
| 3046 | which holds the state of the random number generator. The | 3048 | that holds the state of the random number generator. The |
| 3047 | function modifies this state object as a side effect. If | 3049 | function modifies this state object as a side effect. If |
| 3048 | @var{state} is omitted, it defaults to the variable | 3050 | @var{state} is omitted, it defaults to the internal variable |
| 3049 | @code{cl--random-state}, which contains a pre-initialized | 3051 | @code{cl--random-state}, which contains a pre-initialized |
| 3050 | @code{random-state} object. | 3052 | default @code{random-state} object. (Since any number of programs in |
| 3053 | the Emacs process may be accessing @code{cl--random-state} in | ||
| 3054 | interleaved fashion, the sequence generated from this will be | ||
| 3055 | irreproducible for all intents and purposes.) | ||
| 3051 | @end defun | 3056 | @end defun |
| 3052 | 3057 | ||
| 3053 | @defvar cl--random-state | ||
| 3054 | This variable contains the system ``default'' @code{random-state} | ||
| 3055 | object, used for calls to @code{cl-random} that do not specify an | ||
| 3056 | alternative state object. Since any number of programs in the | ||
| 3057 | Emacs process may be accessing @code{cl--random-state} in interleaved | ||
| 3058 | fashion, the sequence generated from this variable will be | ||
| 3059 | irreproducible for all intents and purposes. | ||
| 3060 | @end defvar | ||
| 3061 | |||
| 3062 | @defun cl-make-random-state &optional state | 3058 | @defun cl-make-random-state &optional state |
| 3063 | This function creates or copies a @code{random-state} object. | 3059 | This function creates or copies a @code{random-state} object. |
| 3064 | If @var{state} is omitted or @code{nil}, it returns a new copy of | 3060 | If @var{state} is omitted or @code{nil}, it returns a new copy of |
| @@ -3094,10 +3090,10 @@ This predicate returns @code{t} if @var{object} is a | |||
| 3094 | @section Implementation Parameters | 3090 | @section Implementation Parameters |
| 3095 | 3091 | ||
| 3096 | @noindent | 3092 | @noindent |
| 3097 | This package defines several useful constants having to with numbers. | 3093 | This package defines several useful constants having to do with |
| 3094 | floating-point numbers. | ||
| 3098 | 3095 | ||
| 3099 | The following parameters have to do with floating-point numbers. | 3096 | It determines their values by exercising the computer's |
| 3100 | This package determines their values by exercising the computer's | ||
| 3101 | floating-point arithmetic in various ways. Because this operation | 3097 | floating-point arithmetic in various ways. Because this operation |
| 3102 | might be slow, the code for initializing them is kept in a separate | 3098 | might be slow, the code for initializing them is kept in a separate |
| 3103 | function that must be called before the parameters can be used. | 3099 | function that must be called before the parameters can be used. |
| @@ -3105,12 +3101,13 @@ function that must be called before the parameters can be used. | |||
| 3105 | @defun cl-float-limits | 3101 | @defun cl-float-limits |
| 3106 | This function makes sure that the Common Lisp floating-point parameters | 3102 | This function makes sure that the Common Lisp floating-point parameters |
| 3107 | like @code{cl-most-positive-float} have been initialized. Until it is | 3103 | like @code{cl-most-positive-float} have been initialized. Until it is |
| 3108 | called, these parameters will be @code{nil}. If this version of Emacs | 3104 | called, these parameters will be @code{nil}. |
| 3109 | does not support floats, the parameters will remain @code{nil}. If the | 3105 | @c If this version of Emacs does not support floats, the parameters will |
| 3110 | parameters have already been initialized, the function returns | 3106 | @c remain @code{nil}. |
| 3107 | If the parameters have already been initialized, the function returns | ||
| 3111 | immediately. | 3108 | immediately. |
| 3112 | 3109 | ||
| 3113 | The algorithm makes assumptions that will be valid for most modern | 3110 | The algorithm makes assumptions that will be valid for almost all |
| 3114 | machines, but will fail if the machine's arithmetic is extremely | 3111 | machines, but will fail if the machine's arithmetic is extremely |
| 3115 | unusual, e.g., decimal. | 3112 | unusual, e.g., decimal. |
| 3116 | @end defun | 3113 | @end defun |
| @@ -3130,7 +3127,7 @@ is approximately @code{1.79e+308}. | |||
| 3130 | @end defvar | 3127 | @end defvar |
| 3131 | 3128 | ||
| 3132 | @defvar cl-most-negative-float | 3129 | @defvar cl-most-negative-float |
| 3133 | This constant equals the most-negative value a Lisp float can hold. | 3130 | This constant equals the most negative value a Lisp float can hold. |
| 3134 | (It is assumed to be equal to @code{(- cl-most-positive-float)}.) | 3131 | (It is assumed to be equal to @code{(- cl-most-positive-float)}.) |
| 3135 | @end defvar | 3132 | @end defvar |
| 3136 | 3133 | ||
| @@ -3199,7 +3196,7 @@ may appear in any order. | |||
| 3199 | The @code{:key} argument should be passed either @code{nil}, or a | 3196 | The @code{:key} argument should be passed either @code{nil}, or a |
| 3200 | function of one argument. This key function is used as a filter | 3197 | function of one argument. This key function is used as a filter |
| 3201 | through which the elements of the sequence are seen; for example, | 3198 | through which the elements of the sequence are seen; for example, |
| 3202 | @code{(cl-find x y :key 'car)} is similar to @code{(cl-assoc x y)}: | 3199 | @code{(cl-find x y :key 'car)} is similar to @code{(cl-assoc x y)}. |
| 3203 | It searches for an element of the list whose @sc{car} equals | 3200 | It searches for an element of the list whose @sc{car} equals |
| 3204 | @code{x}, rather than for an element which equals @code{x} itself. | 3201 | @code{x}, rather than for an element which equals @code{x} itself. |
| 3205 | If @code{:key} is omitted or @code{nil}, the filter is effectively | 3202 | If @code{:key} is omitted or @code{nil}, the filter is effectively |
| @@ -3217,7 +3214,7 @@ true (non-@code{nil}) to indicate a match; instead, you may use | |||
| 3217 | @code{:test-not} to give a function which returns @emph{false} to | 3214 | @code{:test-not} to give a function which returns @emph{false} to |
| 3218 | indicate a match. The default test function is @code{eql}. | 3215 | indicate a match. The default test function is @code{eql}. |
| 3219 | 3216 | ||
| 3220 | Many functions which take @var{item} and @code{:test} or @code{:test-not} | 3217 | Many functions that take @var{item} and @code{:test} or @code{:test-not} |
| 3221 | arguments also come in @code{-if} and @code{-if-not} varieties, | 3218 | arguments also come in @code{-if} and @code{-if-not} varieties, |
| 3222 | where a @var{predicate} function is passed instead of @var{item}, | 3219 | where a @var{predicate} function is passed instead of @var{item}, |
| 3223 | and sequence elements match if the predicate returns true on them | 3220 | and sequence elements match if the predicate returns true on them |
| @@ -3231,7 +3228,7 @@ and sequence elements match if the predicate returns true on them | |||
| 3231 | to remove all zeros from sequence @code{seq}. | 3228 | to remove all zeros from sequence @code{seq}. |
| 3232 | 3229 | ||
| 3233 | Some operations can work on a subsequence of the argument sequence; | 3230 | Some operations can work on a subsequence of the argument sequence; |
| 3234 | these function take @code{:start} and @code{:end} arguments which | 3231 | these function take @code{:start} and @code{:end} arguments, which |
| 3235 | default to zero and the length of the sequence, respectively. | 3232 | default to zero and the length of the sequence, respectively. |
| 3236 | Only elements between @var{start} (inclusive) and @var{end} | 3233 | Only elements between @var{start} (inclusive) and @var{end} |
| 3237 | (exclusive) are affected by the operation. The @var{end} argument | 3234 | (exclusive) are affected by the operation. The @var{end} argument |
| @@ -3339,7 +3336,7 @@ the return values using @code{nconc}. | |||
| 3339 | @defun cl-some predicate seq &rest more-seqs | 3336 | @defun cl-some predicate seq &rest more-seqs |
| 3340 | This function calls @var{predicate} on each element of @var{seq} | 3337 | This function calls @var{predicate} on each element of @var{seq} |
| 3341 | in turn; if @var{predicate} returns a non-@code{nil} value, | 3338 | in turn; if @var{predicate} returns a non-@code{nil} value, |
| 3342 | @code{some} returns that value, otherwise it returns @code{nil}. | 3339 | @code{cl-some} returns that value, otherwise it returns @code{nil}. |
| 3343 | Given several sequence arguments, it steps through the sequences | 3340 | Given several sequence arguments, it steps through the sequences |
| 3344 | in parallel until the shortest one runs out, just as in | 3341 | in parallel until the shortest one runs out, just as in |
| 3345 | @code{cl-mapcar}. You can rely on the left-to-right order in which | 3342 | @code{cl-mapcar}. You can rely on the left-to-right order in which |
| @@ -3388,7 +3385,7 @@ of left-associative: | |||
| 3388 | @equiv{} (- 1 (- 2 (- 3 4))) @result{} -2 | 3385 | @equiv{} (- 1 (- 2 (- 3 4))) @result{} -2 |
| 3389 | @end example | 3386 | @end example |
| 3390 | 3387 | ||
| 3391 | If @code{:key} is specified, it is a function of one argument which | 3388 | If @code{:key} is specified, it is a function of one argument, which |
| 3392 | is called on each of the sequence elements in turn. | 3389 | is called on each of the sequence elements in turn. |
| 3393 | 3390 | ||
| 3394 | If @code{:initial-value} is specified, it is effectively added to the | 3391 | If @code{:initial-value} is specified, it is effectively added to the |
| @@ -3457,7 +3454,7 @@ of data copied is simply the shorter of the source and destination | |||
| 3457 | If @var{seq1} and @var{seq2} are @code{eq}, then the replacement | 3454 | If @var{seq1} and @var{seq2} are @code{eq}, then the replacement |
| 3458 | will work correctly even if the regions indicated by the start | 3455 | will work correctly even if the regions indicated by the start |
| 3459 | and end arguments overlap. However, if @var{seq1} and @var{seq2} | 3456 | and end arguments overlap. However, if @var{seq1} and @var{seq2} |
| 3460 | are lists which share storage but are not @code{eq}, and the | 3457 | are lists that share storage but are not @code{eq}, and the |
| 3461 | start and end arguments specify overlapping regions, the effect | 3458 | start and end arguments specify overlapping regions, the effect |
| 3462 | is undefined. | 3459 | is undefined. |
| 3463 | @end defun | 3460 | @end defun |
| @@ -3480,7 +3477,7 @@ if @var{count} was also specified). | |||
| 3480 | @end defun | 3477 | @end defun |
| 3481 | 3478 | ||
| 3482 | @defun cl-delete item seq @t{&key :test :test-not :key :count :start :end :from-end} | 3479 | @defun cl-delete item seq @t{&key :test :test-not :key :count :start :end :from-end} |
| 3483 | This deletes all elements of @var{seq} which match @var{item}. | 3480 | This deletes all elements of @var{seq} that match @var{item}. |
| 3484 | It is a destructive operation. Since Emacs Lisp does not support | 3481 | It is a destructive operation. Since Emacs Lisp does not support |
| 3485 | stretchable strings or vectors, this is the same as @code{cl-remove} | 3482 | stretchable strings or vectors, this is the same as @code{cl-remove} |
| 3486 | for those sequence types. On lists, @code{cl-remove} will copy the | 3483 | for those sequence types. On lists, @code{cl-remove} will copy the |
| @@ -3580,7 +3577,7 @@ elements match (according to @code{:test}, @code{:test-not}, | |||
| 3580 | and @code{:key}), the function returns @code{nil}. If there is | 3577 | and @code{:key}), the function returns @code{nil}. If there is |
| 3581 | a mismatch, the function returns the index (relative to @var{seq1}) | 3578 | a mismatch, the function returns the index (relative to @var{seq1}) |
| 3582 | of the first mismatching element. This will be the leftmost pair of | 3579 | of the first mismatching element. This will be the leftmost pair of |
| 3583 | elements which do not match, or the position at which the shorter of | 3580 | elements that do not match, or the position at which the shorter of |
| 3584 | the two otherwise-matching sequences runs out. | 3581 | the two otherwise-matching sequences runs out. |
| 3585 | 3582 | ||
| 3586 | If @code{:from-end} is true, then the elements are compared from right | 3583 | If @code{:from-end} is true, then the elements are compared from right |
| @@ -3595,7 +3592,7 @@ which compares two strings case-insensitively. | |||
| 3595 | @defun cl-search seq1 seq2 @t{&key :test :test-not :key :from-end :start1 :end1 :start2 :end2} | 3592 | @defun cl-search seq1 seq2 @t{&key :test :test-not :key :from-end :start1 :end1 :start2 :end2} |
| 3596 | This function searches @var{seq2} for a subsequence that matches | 3593 | This function searches @var{seq2} for a subsequence that matches |
| 3597 | @var{seq1} (or part of it specified by @code{:start1} and | 3594 | @var{seq1} (or part of it specified by @code{:start1} and |
| 3598 | @code{:end1}.) Only matches which fall entirely within the region | 3595 | @code{:end1}). Only matches that fall entirely within the region |
| 3599 | defined by @code{:start2} and @code{:end2} will be considered. | 3596 | defined by @code{:start2} and @code{:end2} will be considered. |
| 3600 | The return value is the index of the leftmost element of the | 3597 | The return value is the index of the leftmost element of the |
| 3601 | leftmost match, relative to the start of @var{seq2}, or @code{nil} | 3598 | leftmost match, relative to the start of @var{seq2}, or @code{nil} |
| @@ -3606,7 +3603,7 @@ function finds the @emph{rightmost} matching subsequence. | |||
| 3606 | @node Sorting Sequences | 3603 | @node Sorting Sequences |
| 3607 | @section Sorting Sequences | 3604 | @section Sorting Sequences |
| 3608 | 3605 | ||
| 3609 | @defun clsort seq predicate @t{&key :key} | 3606 | @defun cl-sort seq predicate @t{&key :key} |
| 3610 | This function sorts @var{seq} into increasing order as determined | 3607 | This function sorts @var{seq} into increasing order as determined |
| 3611 | by using @var{predicate} to compare pairs of elements. @var{predicate} | 3608 | by using @var{predicate} to compare pairs of elements. @var{predicate} |
| 3612 | should return true (non-@code{nil}) if and only if its first argument | 3609 | should return true (non-@code{nil}) if and only if its first argument |
| @@ -3617,7 +3614,7 @@ numbers into decreasing rather than increasing order. | |||
| 3617 | 3614 | ||
| 3618 | This function differs from Emacs's built-in @code{sort} in that it | 3615 | This function differs from Emacs's built-in @code{sort} in that it |
| 3619 | can operate on any type of sequence, not just lists. Also, it | 3616 | can operate on any type of sequence, not just lists. Also, it |
| 3620 | accepts a @code{:key} argument which is used to preprocess data | 3617 | accepts a @code{:key} argument, which is used to preprocess data |
| 3621 | fed to the @var{predicate} function. For example, | 3618 | fed to the @var{predicate} function. For example, |
| 3622 | 3619 | ||
| 3623 | @example | 3620 | @example |
| @@ -3628,7 +3625,7 @@ fed to the @var{predicate} function. For example, | |||
| 3628 | sorts @var{data}, a sequence of strings, into increasing alphabetical | 3625 | sorts @var{data}, a sequence of strings, into increasing alphabetical |
| 3629 | order without regard to case. A @code{:key} function of @code{car} | 3626 | order without regard to case. A @code{:key} function of @code{car} |
| 3630 | would be useful for sorting association lists. It should only be a | 3627 | would be useful for sorting association lists. It should only be a |
| 3631 | simple accessor though, it's used heavily in the current | 3628 | simple accessor though, since it's used heavily in the current |
| 3632 | implementation. | 3629 | implementation. |
| 3633 | 3630 | ||
| 3634 | The @code{cl-sort} function is destructive; it sorts lists by actually | 3631 | The @code{cl-sort} function is destructive; it sorts lists by actually |
| @@ -3684,7 +3681,7 @@ i.e., chains of cons cells. | |||
| 3684 | 3681 | ||
| 3685 | @defun cl-caddr x | 3682 | @defun cl-caddr x |
| 3686 | This function is equivalent to @code{(car (cdr (cdr @var{x})))}. | 3683 | This function is equivalent to @code{(car (cdr (cdr @var{x})))}. |
| 3687 | Likewise, this package defines all 28 @code{c@var{xxx}r} functions | 3684 | Likewise, this package defines all 24 @code{c@var{xxx}r} functions |
| 3688 | where @var{xxx} is up to four @samp{a}s and/or @samp{d}s. | 3685 | where @var{xxx} is up to four @samp{a}s and/or @samp{d}s. |
| 3689 | All of these functions are @code{setf}-able, and calls to them | 3686 | All of these functions are @code{setf}-able, and calls to them |
| 3690 | are expanded inline by the byte-compiler for maximum efficiency. | 3687 | are expanded inline by the byte-compiler for maximum efficiency. |
| @@ -3712,7 +3709,8 @@ This function returns the length of list @var{x}, exactly like | |||
| 3712 | @code{(length @var{x})}, except that if @var{x} is a circular | 3709 | @code{(length @var{x})}, except that if @var{x} is a circular |
| 3713 | list (where the @sc{cdr}-chain forms a loop rather than terminating | 3710 | list (where the @sc{cdr}-chain forms a loop rather than terminating |
| 3714 | with @code{nil}), this function returns @code{nil}. (The regular | 3711 | with @code{nil}), this function returns @code{nil}. (The regular |
| 3715 | @code{length} function would get stuck if given a circular list.) | 3712 | @code{length} function would get stuck if given a circular list. |
| 3713 | See also the @code{safe-length} function.) | ||
| 3716 | @end defun | 3714 | @end defun |
| 3717 | 3715 | ||
| 3718 | @defun cl-list* arg &rest others | 3716 | @defun cl-list* arg &rest others |
| @@ -3740,18 +3738,6 @@ This function returns a copy of the list @var{list}. It copies | |||
| 3740 | dotted lists like @code{(1 2 . 3)} correctly. | 3738 | dotted lists like @code{(1 2 . 3)} correctly. |
| 3741 | @end defun | 3739 | @end defun |
| 3742 | 3740 | ||
| 3743 | @defun copy-tree x &optional vecp | ||
| 3744 | This function returns a copy of the tree of cons cells @var{x}. | ||
| 3745 | @c FIXME? cl-copy-list is not an alias of copy-sequence. | ||
| 3746 | Unlike @code{copy-sequence} (and its alias @code{cl-copy-list}), | ||
| 3747 | which copies only along the @sc{cdr} direction, this function | ||
| 3748 | copies (recursively) along both the @sc{car} and the @sc{cdr} | ||
| 3749 | directions. If @var{x} is not a cons cell, the function simply | ||
| 3750 | returns @var{x} unchanged. If the optional @var{vecp} argument | ||
| 3751 | is true, this function copies vectors (recursively) as well as | ||
| 3752 | cons cells. | ||
| 3753 | @end defun | ||
| 3754 | |||
| 3755 | @defun cl-tree-equal x y @t{&key :test :test-not :key} | 3741 | @defun cl-tree-equal x y @t{&key :test :test-not :key} |
| 3756 | This function compares two trees of cons cells. If @var{x} and | 3742 | This function compares two trees of cons cells. If @var{x} and |
| 3757 | @var{y} are both cons cells, their @sc{car}s and @sc{cdr}s are | 3743 | @var{y} are both cons cells, their @sc{car}s and @sc{cdr}s are |
| @@ -3814,7 +3800,7 @@ This is a destructive version of @code{cl-sublis}. | |||
| 3814 | @section Lists as Sets | 3800 | @section Lists as Sets |
| 3815 | 3801 | ||
| 3816 | @noindent | 3802 | @noindent |
| 3817 | These functions perform operations on lists which represent sets | 3803 | These functions perform operations on lists that represent sets |
| 3818 | of elements. | 3804 | of elements. |
| 3819 | 3805 | ||
| 3820 | @defun cl-member item list @t{&key :test :test-not :key} | 3806 | @defun cl-member item list @t{&key :test :test-not :key} |
| @@ -3827,13 +3813,14 @@ are compared by @code{eql} by default; you can use the @code{:test}, | |||
| 3827 | 3813 | ||
| 3828 | The standard Emacs lisp function @code{member} uses @code{equal} for | 3814 | The standard Emacs lisp function @code{member} uses @code{equal} for |
| 3829 | comparisons; it is equivalent to @code{(cl-member @var{item} @var{list} | 3815 | comparisons; it is equivalent to @code{(cl-member @var{item} @var{list} |
| 3830 | :test 'equal)}. | 3816 | :test 'equal)}. With no keyword arguments, @code{cl-member} is |
| 3817 | equivalent to @code{memq}. | ||
| 3831 | @end defun | 3818 | @end defun |
| 3832 | 3819 | ||
| 3833 | @findex cl-member-if | 3820 | @findex cl-member-if |
| 3834 | @findex cl-member-if-not | 3821 | @findex cl-member-if-not |
| 3835 | The @code{cl-member-if} and @code{cl-member-if-not} functions | 3822 | The @code{cl-member-if} and @code{cl-member-if-not} functions |
| 3836 | analogously search for elements which satisfy a given predicate. | 3823 | analogously search for elements that satisfy a given predicate. |
| 3837 | 3824 | ||
| 3838 | @defun cl-tailp sublist list | 3825 | @defun cl-tailp sublist list |
| 3839 | This function returns @code{t} if @var{sublist} is a sublist of | 3826 | This function returns @code{t} if @var{sublist} is a sublist of |
| @@ -3852,11 +3839,11 @@ become part of the list. | |||
| 3852 | @end defun | 3839 | @end defun |
| 3853 | 3840 | ||
| 3854 | @defun cl-union list1 list2 @t{&key :test :test-not :key} | 3841 | @defun cl-union list1 list2 @t{&key :test :test-not :key} |
| 3855 | This function combines two lists which represent sets of items, | 3842 | This function combines two lists that represent sets of items, |
| 3856 | returning a list that represents the union of those two sets. | 3843 | returning a list that represents the union of those two sets. |
| 3857 | The result list will contain all items which appear in @var{list1} | 3844 | The resulting list contains all items that appear in @var{list1} |
| 3858 | or @var{list2}, and no others. If an item appears in both | 3845 | or @var{list2}, and no others. If an item appears in both |
| 3859 | @var{list1} and @var{list2} it will be copied only once. If | 3846 | @var{list1} and @var{list2} it is copied only once. If |
| 3860 | an item is duplicated in @var{list1} or @var{list2}, it is | 3847 | an item is duplicated in @var{list1} or @var{list2}, it is |
| 3861 | undefined whether or not that duplication will survive in the | 3848 | undefined whether or not that duplication will survive in the |
| 3862 | result list. The order of elements in the result list is also | 3849 | result list. The order of elements in the result list is also |
| @@ -3871,7 +3858,7 @@ it tries to reuse the storage of the argument lists if possible. | |||
| 3871 | @defun cl-intersection list1 list2 @t{&key :test :test-not :key} | 3858 | @defun cl-intersection list1 list2 @t{&key :test :test-not :key} |
| 3872 | This function computes the intersection of the sets represented | 3859 | This function computes the intersection of the sets represented |
| 3873 | by @var{list1} and @var{list2}. It returns the list of items | 3860 | by @var{list1} and @var{list2}. It returns the list of items |
| 3874 | which appear in both @var{list1} and @var{list2}. | 3861 | that appear in both @var{list1} and @var{list2}. |
| 3875 | @end defun | 3862 | @end defun |
| 3876 | 3863 | ||
| 3877 | @defun cl-nintersection list1 list2 @t{&key :test :test-not :key} | 3864 | @defun cl-nintersection list1 list2 @t{&key :test :test-not :key} |
| @@ -3921,7 +3908,7 @@ This function searches the association list @var{a-list} for an | |||
| 3921 | element whose @sc{car} matches (in the sense of @code{:test}, | 3908 | element whose @sc{car} matches (in the sense of @code{:test}, |
| 3922 | @code{:test-not}, and @code{:key}, or by comparison with @code{eql}) | 3909 | @code{:test-not}, and @code{:key}, or by comparison with @code{eql}) |
| 3923 | a given @var{item}. It returns the matching element, if any, | 3910 | a given @var{item}. It returns the matching element, if any, |
| 3924 | otherwise @code{nil}. It ignores elements of @var{a-list} which | 3911 | otherwise @code{nil}. It ignores elements of @var{a-list} that |
| 3925 | are not cons cells. (This corresponds to the behavior of | 3912 | are not cons cells. (This corresponds to the behavior of |
| 3926 | @code{assq} and @code{assoc} in Emacs Lisp; Common Lisp's | 3913 | @code{assq} and @code{assoc} in Emacs Lisp; Common Lisp's |
| 3927 | @code{assoc} ignores @code{nil}s but considers any other non-cons | 3914 | @code{assoc} ignores @code{nil}s but considers any other non-cons |
| @@ -3982,11 +3969,11 @@ are symbols. For example, | |||
| 3982 | @end example | 3969 | @end example |
| 3983 | 3970 | ||
| 3984 | @noindent | 3971 | @noindent |
| 3985 | defines a struct type called @code{person} which contains three | 3972 | defines a struct type called @code{person} that contains three |
| 3986 | slots. Given a @code{person} object @var{p}, you can access those | 3973 | slots. Given a @code{person} object @var{p}, you can access those |
| 3987 | slots by calling @code{(person-name @var{p})}, @code{(person-age @var{p})}, | 3974 | slots by calling @code{(person-name @var{p})}, @code{(person-age @var{p})}, |
| 3988 | and @code{(person-sex @var{p})}. You can also change these slots by | 3975 | and @code{(person-sex @var{p})}. You can also change these slots by |
| 3989 | using @code{setf} on any of these place forms: | 3976 | using @code{setf} on any of these place forms, for example: |
| 3990 | 3977 | ||
| 3991 | @example | 3978 | @example |
| 3992 | (cl-incf (person-age birthday-boy)) | 3979 | (cl-incf (person-age birthday-boy)) |
| @@ -4003,10 +3990,10 @@ Given a @code{person}, @code{(copy-person @var{p})} makes a new | |||
| 4003 | object of the same type whose slots are @code{eq} to those of @var{p}. | 3990 | object of the same type whose slots are @code{eq} to those of @var{p}. |
| 4004 | 3991 | ||
| 4005 | Given any Lisp object @var{x}, @code{(person-p @var{x})} returns | 3992 | Given any Lisp object @var{x}, @code{(person-p @var{x})} returns |
| 4006 | true if @var{x} looks like a @code{person}, false otherwise. (Again, | 3993 | true if @var{x} looks like a @code{person}, and false otherwise. (Again, |
| 4007 | in Common Lisp this predicate would be exact; in Emacs Lisp the | 3994 | in Common Lisp this predicate would be exact; in Emacs Lisp the |
| 4008 | best it can do is verify that @var{x} is a vector of the correct | 3995 | best it can do is verify that @var{x} is a vector of the correct |
| 4009 | length which starts with the correct tag symbol.) | 3996 | length that starts with the correct tag symbol.) |
| 4010 | 3997 | ||
| 4011 | Accessors like @code{person-name} normally check their arguments | 3998 | Accessors like @code{person-name} normally check their arguments |
| 4012 | (effectively using @code{person-p}) and signal an error if the | 3999 | (effectively using @code{person-p}) and signal an error if the |
| @@ -4043,7 +4030,7 @@ In general, @var{name} is either a name symbol or a list of a name | |||
| 4043 | symbol followed by any number of @dfn{struct options}; each @var{slot} | 4030 | symbol followed by any number of @dfn{struct options}; each @var{slot} |
| 4044 | is either a slot symbol or a list of the form @samp{(@var{slot-name} | 4031 | is either a slot symbol or a list of the form @samp{(@var{slot-name} |
| 4045 | @var{default-value} @var{slot-options}@dots{})}. The @var{default-value} | 4032 | @var{default-value} @var{slot-options}@dots{})}. The @var{default-value} |
| 4046 | is a Lisp form which is evaluated any time an instance of the | 4033 | is a Lisp form that is evaluated any time an instance of the |
| 4047 | structure type is created without specifying that slot's value. | 4034 | structure type is created without specifying that slot's value. |
| 4048 | 4035 | ||
| 4049 | Common Lisp defines several slot options, but the only one | 4036 | Common Lisp defines several slot options, but the only one |
| @@ -4101,11 +4088,11 @@ The argument names should match the slot names; each slot is | |||
| 4101 | initialized from the corresponding argument. Slots whose names | 4088 | initialized from the corresponding argument. Slots whose names |
| 4102 | do not appear in the argument list are initialized based on the | 4089 | do not appear in the argument list are initialized based on the |
| 4103 | @var{default-value} in their slot descriptor. Also, @code{&optional} | 4090 | @var{default-value} in their slot descriptor. Also, @code{&optional} |
| 4104 | and @code{&key} arguments which don't specify defaults take their | 4091 | and @code{&key} arguments that don't specify defaults take their |
| 4105 | defaults from the slot descriptor. It is valid to include arguments | 4092 | defaults from the slot descriptor. It is valid to include arguments |
| 4106 | which don't correspond to slot names; these are useful if they are | 4093 | that don't correspond to slot names; these are useful if they are |
| 4107 | referred to in the defaults for optional, keyword, or @code{&aux} | 4094 | referred to in the defaults for optional, keyword, or @code{&aux} |
| 4108 | arguments which @emph{do} correspond to slots. | 4095 | arguments that @emph{do} correspond to slots. |
| 4109 | 4096 | ||
| 4110 | You can specify any number of full-format @code{:constructor} | 4097 | You can specify any number of full-format @code{:constructor} |
| 4111 | options on a structure. The default constructor is still generated | 4098 | options on a structure. The default constructor is still generated |
| @@ -4146,7 +4133,7 @@ means not to generate a copier function. (In this implementation, | |||
| 4146 | all copier functions are simply synonyms for @code{copy-sequence}.) | 4133 | all copier functions are simply synonyms for @code{copy-sequence}.) |
| 4147 | 4134 | ||
| 4148 | @item :predicate | 4135 | @item :predicate |
| 4149 | The argument is an alternate name for the predicate which recognizes | 4136 | The argument is an alternate name for the predicate that recognizes |
| 4150 | objects of this type. The default is @code{@var{name}-p}. @code{nil} | 4137 | objects of this type. The default is @code{@var{name}-p}. @code{nil} |
| 4151 | means not to generate a predicate function. (If the @code{:type} | 4138 | means not to generate a predicate function. (If the @code{:type} |
| 4152 | option is used without the @code{:named} option, no predicate is | 4139 | option is used without the @code{:named} option, no predicate is |
| @@ -4206,7 +4193,7 @@ work on astronauts just like other people. | |||
| 4206 | 4193 | ||
| 4207 | @item :print-function | 4194 | @item :print-function |
| 4208 | In full Common Lisp, this option allows you to specify a function | 4195 | In full Common Lisp, this option allows you to specify a function |
| 4209 | which is called to print an instance of the structure type. The | 4196 | that is called to print an instance of the structure type. The |
| 4210 | Emacs Lisp system offers no hooks into the Lisp printer which would | 4197 | Emacs Lisp system offers no hooks into the Lisp printer which would |
| 4211 | allow for such a feature, so this package simply ignores | 4198 | allow for such a feature, so this package simply ignores |
| 4212 | @code{:print-function}. | 4199 | @code{:print-function}. |
| @@ -4383,7 +4370,7 @@ You can find out how a macro expands by using the | |||
| 4383 | This function takes a single Lisp form as an argument and inserts | 4370 | This function takes a single Lisp form as an argument and inserts |
| 4384 | a nicely formatted copy of it in the current buffer (which must be | 4371 | a nicely formatted copy of it in the current buffer (which must be |
| 4385 | in Lisp mode so that indentation works properly). It also expands | 4372 | in Lisp mode so that indentation works properly). It also expands |
| 4386 | all Lisp macros which appear in the form. The easiest way to use | 4373 | all Lisp macros that appear in the form. The easiest way to use |
| 4387 | this function is to go to the @file{*scratch*} buffer and type, say, | 4374 | this function is to go to the @file{*scratch*} buffer and type, say, |
| 4388 | 4375 | ||
| 4389 | @example | 4376 | @example |
| @@ -4392,7 +4379,7 @@ this function is to go to the @file{*scratch*} buffer and type, say, | |||
| 4392 | 4379 | ||
| 4393 | @noindent | 4380 | @noindent |
| 4394 | and type @kbd{C-x C-e} immediately after the closing parenthesis; | 4381 | and type @kbd{C-x C-e} immediately after the closing parenthesis; |
| 4395 | the expansion | 4382 | an expansion similar to: |
| 4396 | 4383 | ||
| 4397 | @example | 4384 | @example |
| 4398 | (cl-block nil | 4385 | (cl-block nil |
| @@ -4413,7 +4400,11 @@ variable @code{G1004} was created by @code{cl-gensym}.) | |||
| 4413 | If the optional argument @var{full} is true, then @emph{all} | 4400 | If the optional argument @var{full} is true, then @emph{all} |
| 4414 | macros are expanded, including @code{cl-block}, @code{cl-eval-when}, | 4401 | macros are expanded, including @code{cl-block}, @code{cl-eval-when}, |
| 4415 | and compiler macros. Expansion is done as if @var{form} were | 4402 | and compiler macros. Expansion is done as if @var{form} were |
| 4416 | a top-level form in a file being compiled. For example, | 4403 | a top-level form in a file being compiled. |
| 4404 | |||
| 4405 | @c FIXME none of these examples are still applicable. | ||
| 4406 | @ignore | ||
| 4407 | For example, | ||
| 4417 | 4408 | ||
| 4418 | @example | 4409 | @example |
| 4419 | (cl-prettyexpand '(cl-pushnew 'x list)) | 4410 | (cl-prettyexpand '(cl-pushnew 'x list)) |
| @@ -4423,16 +4414,12 @@ a top-level form in a file being compiled. For example, | |||
| 4423 | (cl-prettyexpand '(caddr (cl-member 'a list)) t) | 4414 | (cl-prettyexpand '(caddr (cl-member 'a list)) t) |
| 4424 | @print{} (car (cdr (cdr (memq 'a list)))) | 4415 | @print{} (car (cdr (cdr (memq 'a list)))) |
| 4425 | @end example | 4416 | @end example |
| 4417 | @end ignore | ||
| 4426 | 4418 | ||
| 4427 | Note that @code{cl-adjoin}, @code{cl-caddr}, and @code{cl-member} all | 4419 | Note that @code{cl-adjoin}, @code{cl-caddr}, and @code{cl-member} all |
| 4428 | have built-in compiler macros to optimize them in common cases. | 4420 | have built-in compiler macros to optimize them in common cases. |
| 4429 | @end defun | 4421 | @end defun |
| 4430 | 4422 | ||
| 4431 | @ifinfo | ||
| 4432 | @example | ||
| 4433 | |||
| 4434 | @end example | ||
| 4435 | @end ifinfo | ||
| 4436 | @appendixsec Error Checking | 4423 | @appendixsec Error Checking |
| 4437 | 4424 | ||
| 4438 | @noindent | 4425 | @noindent |
| @@ -4442,7 +4429,7 @@ where substantial gains were possible at the expense of marginal | |||
| 4442 | incompatibility. | 4429 | incompatibility. |
| 4443 | 4430 | ||
| 4444 | The Common Lisp standard (as embodied in Steele's book) uses the | 4431 | The Common Lisp standard (as embodied in Steele's book) uses the |
| 4445 | phrase ``it is an error if'' to indicate a situation which is not | 4432 | phrase ``it is an error if'' to indicate a situation that is not |
| 4446 | supposed to arise in complying programs; implementations are strongly | 4433 | supposed to arise in complying programs; implementations are strongly |
| 4447 | encouraged but not required to signal an error in these situations. | 4434 | encouraged but not required to signal an error in these situations. |
| 4448 | This package sometimes omits such error checking in the interest of | 4435 | This package sometimes omits such error checking in the interest of |
| @@ -4464,45 +4451,43 @@ you can use @code{&allow-other-keys} to omit this check. Functions | |||
| 4464 | defined in this package such as @code{cl-find} and @code{cl-member} | 4451 | defined in this package such as @code{cl-find} and @code{cl-member} |
| 4465 | do check their keyword arguments for validity. | 4452 | do check their keyword arguments for validity. |
| 4466 | 4453 | ||
| 4467 | @ifinfo | 4454 | @appendixsec Compiler Optimizations |
| 4468 | @example | ||
| 4469 | |||
| 4470 | @end example | ||
| 4471 | @end ifinfo | ||
| 4472 | @appendixsec Optimizing Compiler | ||
| 4473 | 4455 | ||
| 4474 | @noindent | 4456 | @noindent |
| 4475 | Use of the optimizing Emacs compiler is highly recommended; many of the Common | 4457 | Changing the value of @code{byte-optimize} from the default @code{t} |
| 4458 | is highly discouraged; many of the Common | ||
| 4476 | Lisp macros emit | 4459 | Lisp macros emit |
| 4477 | code which can be improved by optimization. In particular, | 4460 | code that can be improved by optimization. In particular, |
| 4478 | @code{cl-block}s (whether explicit or implicit in constructs like | 4461 | @code{cl-block}s (whether explicit or implicit in constructs like |
| 4479 | @code{cl-defun} and @code{cl-loop}) carry a fair run-time penalty; the | 4462 | @code{cl-defun} and @code{cl-loop}) carry a fair run-time penalty; the |
| 4480 | optimizing compiler removes @code{cl-block}s which are not actually | 4463 | byte-compiler removes @code{cl-block}s that are not actually |
| 4481 | referenced by @code{cl-return} or @code{cl-return-from} inside the block. | 4464 | referenced by @code{cl-return} or @code{cl-return-from} inside the block. |
| 4482 | 4465 | ||
| 4483 | @node Common Lisp Compatibility | 4466 | @node Common Lisp Compatibility |
| 4484 | @appendix Common Lisp Compatibility | 4467 | @appendix Common Lisp Compatibility |
| 4485 | 4468 | ||
| 4486 | @noindent | 4469 | @noindent |
| 4487 | Following is a list of all known incompatibilities between this | 4470 | The following is a list of all known incompatibilities between this |
| 4488 | package and Common Lisp as documented in Steele (2nd edition). | 4471 | package and Common Lisp as documented in Steele (2nd edition). |
| 4489 | 4472 | ||
| 4490 | The word @code{cl-defun} is required instead of @code{defun} in order | 4473 | The word @code{cl-defun} is required instead of @code{defun} in order |
| 4491 | to use extended Common Lisp argument lists in a function. Likewise, | 4474 | to use extended Common Lisp argument lists in a function. Likewise, |
| 4492 | @code{cl-defmacro} and @code{cl-function} are versions of those forms | 4475 | @code{cl-defmacro} and @code{cl-function} are versions of those forms |
| 4493 | which understand full-featured argument lists. The @code{&whole} | 4476 | which understand full-featured argument lists. The @code{&whole} |
| 4494 | keyword does not work in @code{defmacro} argument lists (except | 4477 | keyword does not work in @code{cl-defmacro} argument lists (except |
| 4495 | inside recursive argument lists). | 4478 | inside recursive argument lists). |
| 4496 | 4479 | ||
| 4497 | The @code{equal} predicate does not distinguish | 4480 | The @code{equal} predicate does not distinguish |
| 4498 | between IEEE floating-point plus and minus zero. The @code{cl-equalp} | 4481 | between IEEE floating-point plus and minus zero. The @code{cl-equalp} |
| 4499 | predicate has several differences with Common Lisp; @pxref{Predicates}. | 4482 | predicate has several differences with Common Lisp; @pxref{Predicates}. |
| 4500 | 4483 | ||
| 4501 | @c FIXME no longer provided by cl. | 4484 | @c FIXME consider moving to lispref |
| 4485 | @ignore | ||
| 4502 | The @code{setf} mechanism is entirely compatible, except that | 4486 | The @code{setf} mechanism is entirely compatible, except that |
| 4503 | setf-methods return a list of five values rather than five | 4487 | setf-methods return a list of five values rather than five |
| 4504 | values directly. Also, the new ``@code{setf} function'' concept | 4488 | values directly. Also, the new ``@code{setf} function'' concept |
| 4505 | (typified by @code{(defun (setf foo) @dots{})}) is not implemented. | 4489 | (typified by @code{(defun (setf foo) @dots{})}) is not implemented. |
| 4490 | @end ignore | ||
| 4506 | 4491 | ||
| 4507 | The @code{cl-do-all-symbols} form is the same as @code{cl-do-symbols} | 4492 | The @code{cl-do-all-symbols} form is the same as @code{cl-do-symbols} |
| 4508 | with no @var{obarray} argument. In Common Lisp, this form would | 4493 | with no @var{obarray} argument. In Common Lisp, this form would |
| @@ -4635,7 +4620,7 @@ However, the Emacs parser does not understand colons and just | |||
| 4635 | treats them as part of the symbol name. Thus, while @code{mapcar} | 4620 | treats them as part of the symbol name. Thus, while @code{mapcar} |
| 4636 | and @code{lisp:mapcar} may refer to the same symbol in Common | 4621 | and @code{lisp:mapcar} may refer to the same symbol in Common |
| 4637 | Lisp, they are totally distinct in Emacs Lisp. Common Lisp | 4622 | Lisp, they are totally distinct in Emacs Lisp. Common Lisp |
| 4638 | programs which refer to a symbol by the full name sometimes | 4623 | programs that refer to a symbol by the full name sometimes |
| 4639 | and the short name other times will not port cleanly to Emacs. | 4624 | and the short name other times will not port cleanly to Emacs. |
| 4640 | 4625 | ||
| 4641 | Emacs Lisp does have a concept of ``obarrays'', which are | 4626 | Emacs Lisp does have a concept of ``obarrays'', which are |
| @@ -4922,8 +4907,9 @@ Common Lisp defines three macros, @code{define-modify-macro}, | |||
| 4922 | @code{defsetf}, and @code{define-setf-method}, that allow the | 4907 | @code{defsetf}, and @code{define-setf-method}, that allow the |
| 4923 | user to extend generalized variables in various ways. | 4908 | user to extend generalized variables in various ways. |
| 4924 | In Emacs, these are obsolete, replaced by various features of | 4909 | In Emacs, these are obsolete, replaced by various features of |
| 4925 | @file{gv.el} in Emacs 24.3. | 4910 | @file{gv.el} in Emacs 24.3. Many of the implementation |
| 4926 | @c FIXME details. | 4911 | details in the following are out-of-date. |
| 4912 | @c FIXME this whole section needs updating. | ||
| 4927 | 4913 | ||
| 4928 | @defmac define-modify-macro name arglist function [doc-string] | 4914 | @defmac define-modify-macro name arglist function [doc-string] |
| 4929 | This macro defines a ``read-modify-write'' macro similar to | 4915 | This macro defines a ``read-modify-write'' macro similar to |
| @@ -4992,7 +4978,7 @@ Otherwise, the above expansion would not obey the rules for the way | |||
| 4992 | @code{setf} is supposed to behave. | 4978 | @code{setf} is supposed to behave. |
| 4993 | 4979 | ||
| 4994 | As a special (non-Common-Lisp) extension, a third argument of @code{t} | 4980 | As a special (non-Common-Lisp) extension, a third argument of @code{t} |
| 4995 | to @code{defsetf} says that the @code{update-fn}'s return value is | 4981 | to @code{defsetf} says that the return value of @code{update-fn} is |
| 4996 | not suitable, so that the above @code{setf} should be expanded to | 4982 | not suitable, so that the above @code{setf} should be expanded to |
| 4997 | something more like | 4983 | something more like |
| 4998 | 4984 | ||
| @@ -5015,7 +5001,7 @@ suite of setf methods, are: | |||
| 5015 | @defmac defsetf access-fn arglist (store-var) forms@dots{} | 5001 | @defmac defsetf access-fn arglist (store-var) forms@dots{} |
| 5016 | This is the second, more complex, form of @code{defsetf}. It is | 5002 | This is the second, more complex, form of @code{defsetf}. It is |
| 5017 | rather like @code{defmacro} except for the additional @var{store-var} | 5003 | rather like @code{defmacro} except for the additional @var{store-var} |
| 5018 | argument. The @var{forms} should return a Lisp form which stores | 5004 | argument. The @var{forms} should return a Lisp form that stores |
| 5019 | the value of @var{store-var} into the generalized variable formed | 5005 | the value of @var{store-var} into the generalized variable formed |
| 5020 | by a call to @var{access-fn} with arguments described by @var{arglist}. | 5006 | by a call to @var{access-fn} with arguments described by @var{arglist}. |
| 5021 | The @var{forms} may begin with a string which documents the @code{setf} | 5007 | The @var{forms} may begin with a string which documents the @code{setf} |
| @@ -5031,7 +5017,7 @@ For example, the simple form of @code{defsetf} is shorthand for | |||
| 5031 | 5017 | ||
| 5032 | The Lisp form that is returned can access the arguments from | 5018 | The Lisp form that is returned can access the arguments from |
| 5033 | @var{arglist} and @var{store-var} in an unrestricted fashion; | 5019 | @var{arglist} and @var{store-var} in an unrestricted fashion; |
| 5034 | macros like @code{setf} and @code{cl-incf} which invoke this | 5020 | macros like @code{cl-incf} that invoke this |
| 5035 | setf-method will insert temporary variables as needed to make | 5021 | setf-method will insert temporary variables as needed to make |
| 5036 | sure the apparent order of evaluation is preserved. | 5022 | sure the apparent order of evaluation is preserved. |
| 5037 | 5023 | ||
| @@ -5048,6 +5034,7 @@ This is the most general way to create new place forms. When | |||
| 5048 | a @code{setf} to @var{access-fn} with arguments described by | 5034 | a @code{setf} to @var{access-fn} with arguments described by |
| 5049 | @var{arglist} is expanded, the @var{forms} are evaluated and | 5035 | @var{arglist} is expanded, the @var{forms} are evaluated and |
| 5050 | must return a list of five items: | 5036 | must return a list of five items: |
| 5037 | @c FIXME Is this still true? | ||
| 5051 | 5038 | ||
| 5052 | @enumerate | 5039 | @enumerate |
| 5053 | @item | 5040 | @item |
| @@ -5063,12 +5050,12 @@ A list of exactly one @dfn{store variable} (generally obtained | |||
| 5063 | from a call to @code{gensym}). | 5050 | from a call to @code{gensym}). |
| 5064 | 5051 | ||
| 5065 | @item | 5052 | @item |
| 5066 | A Lisp form which stores the contents of the store variable into | 5053 | A Lisp form that stores the contents of the store variable into |
| 5067 | the generalized variable, assuming the temporaries have been | 5054 | the generalized variable, assuming the temporaries have been |
| 5068 | bound as described above. | 5055 | bound as described above. |
| 5069 | 5056 | ||
| 5070 | @item | 5057 | @item |
| 5071 | A Lisp form which accesses the contents of the generalized variable, | 5058 | A Lisp form that accesses the contents of the generalized variable, |
| 5072 | assuming the temporaries have been bound. | 5059 | assuming the temporaries have been bound. |
| 5073 | @end enumerate | 5060 | @end enumerate |
| 5074 | 5061 | ||
| @@ -5084,7 +5071,8 @@ temporary variables. In the setf-methods generated by | |||
| 5084 | @code{defsetf}, the second return value is simply the list of | 5071 | @code{defsetf}, the second return value is simply the list of |
| 5085 | arguments in the place form, and the first return value is a | 5072 | arguments in the place form, and the first return value is a |
| 5086 | list of a corresponding number of temporary variables generated | 5073 | list of a corresponding number of temporary variables generated |
| 5087 | by @code{cl-gensym}. Macros like @code{setf} and @code{cl-incf} which | 5074 | @c FIXME I don't think this is true anymore. |
| 5075 | by @code{cl-gensym}. Macros like @code{cl-incf} that | ||
| 5088 | use this setf-method will optimize away most temporaries that | 5076 | use this setf-method will optimize away most temporaries that |
| 5089 | turn out to be unnecessary, so there is little reason for the | 5077 | turn out to be unnecessary, so there is little reason for the |
| 5090 | setf-method itself to optimize. | 5078 | setf-method itself to optimize. |
| @@ -5095,12 +5083,14 @@ This function returns the setf-method for @var{place}, by | |||
| 5095 | invoking the definition previously recorded by @code{defsetf} | 5083 | invoking the definition previously recorded by @code{defsetf} |
| 5096 | or @code{define-setf-method}. The result is a list of five | 5084 | or @code{define-setf-method}. The result is a list of five |
| 5097 | values as described above. You can use this function to build | 5085 | values as described above. You can use this function to build |
| 5098 | your own @code{cl-incf}-like modify macros. (Actually, it is | 5086 | your own @code{cl-incf}-like modify macros. |
| 5099 | @c FIXME? | 5087 | @c These no longer exist. |
| 5100 | better to use the internal functions @code{cl-setf-do-modify} | 5088 | @ignore |
| 5101 | and @code{cl-setf-do-store}, which are a bit easier to use and | 5089 | (Actually, it is better to use the internal functions |
| 5102 | which also do a number of optimizations; consult the source | 5090 | @code{cl-setf-do-modify} and @code{cl-setf-do-store}, which are a bit |
| 5103 | code for the @code{cl-incf} function for a simple example.) | 5091 | easier to use and which also do a number of optimizations; consult the |
| 5092 | source code for the @code{cl-incf} function for a simple example.) | ||
| 5093 | @end ignore | ||
| 5104 | 5094 | ||
| 5105 | The argument @var{env} specifies the ``environment'' to be | 5095 | The argument @var{env} specifies the ``environment'' to be |
| 5106 | passed on to @code{macroexpand} if @code{get-setf-method} should | 5096 | passed on to @code{macroexpand} if @code{get-setf-method} should |
| @@ -5108,12 +5098,14 @@ need to expand a macro in @var{place}. It should come from | |||
| 5108 | an @code{&environment} argument to the macro or setf-method | 5098 | an @code{&environment} argument to the macro or setf-method |
| 5109 | that called @code{get-setf-method}. | 5099 | that called @code{get-setf-method}. |
| 5110 | 5100 | ||
| 5101 | @c FIXME No longer true. | ||
| 5111 | See also the source code for the setf-method for | 5102 | See also the source code for the setf-method for |
| 5112 | @c Also @code{apply}, but that is commented out. | 5103 | @c Also @code{apply}, but that is commented out. |
| 5113 | @code{substring}, which works by calling @code{get-setf-method} on a | 5104 | @code{substring}, which works by calling @code{get-setf-method} on a |
| 5114 | simpler case, then massaging the result. | 5105 | simpler case, then massaging the result. |
| 5115 | @end defun | 5106 | @end defun |
| 5116 | 5107 | ||
| 5108 | @c FIXME does not belong here any more, maybe in lispref? | ||
| 5117 | Modern Common Lisp defines a second, independent way to specify | 5109 | Modern Common Lisp defines a second, independent way to specify |
| 5118 | the @code{setf} behavior of a function, namely ``@code{setf} | 5110 | the @code{setf} behavior of a function, namely ``@code{setf} |
| 5119 | functions'' whose names are lists @code{(setf @var{name})} | 5111 | functions'' whose names are lists @code{(setf @var{name})} |