diff options
| author | Glenn Morris | 2012-10-27 18:55:40 -0700 |
|---|---|---|
| committer | Glenn Morris | 2012-10-27 18:55:40 -0700 |
| commit | 3c0c6155a1ba0179e4099348727ba3243df73be6 (patch) | |
| tree | 8ff89e89583fafe5357f0fda8ade421db28c6f87 | |
| parent | 82b2101791236f7f0b5ee8a39fb05ab0d5e7834f (diff) | |
| download | emacs-3c0c6155a1ba0179e4099348727ba3243df73be6.tar.gz emacs-3c0c6155a1ba0179e4099348727ba3243df73be6.zip | |
Start moving some cl.texi features to an Obsolete appendix
* doc/misc/cl.texi (Lexical Bindings): Move to appendix of obsolete features.
(Porting Common Lisp): Emacs Lisp can do true lexical binding now.
(Obsolete Features): New appendix. Move Lexical Bindings here.
| -rw-r--r-- | doc/misc/ChangeLog | 6 | ||||
| -rw-r--r-- | doc/misc/cl.texi | 297 |
2 files changed, 159 insertions, 144 deletions
diff --git a/doc/misc/ChangeLog b/doc/misc/ChangeLog index 24d8f1cee25..c5d084891f6 100644 --- a/doc/misc/ChangeLog +++ b/doc/misc/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2012-10-28 Glenn Morris <rgm@gnu.org> | ||
| 2 | |||
| 3 | * cl.texi (Lexical Bindings): Move to appendix of obsolete features. | ||
| 4 | (Porting Common Lisp): Emacs Lisp can do true lexical binding now. | ||
| 5 | (Obsolete Features): New appendix. Move Lexical Bindings here. | ||
| 6 | |||
| 1 | 2012-10-27 Glenn Morris <rgm@gnu.org> | 7 | 2012-10-27 Glenn Morris <rgm@gnu.org> |
| 2 | 8 | ||
| 3 | * cl.texi: Use defmac for macros rather than defspec. | 9 | * cl.texi: Use defmac for macros rather than defspec. |
diff --git a/doc/misc/cl.texi b/doc/misc/cl.texi index 09386e2c0c7..46e9dae5319 100644 --- a/doc/misc/cl.texi +++ b/doc/misc/cl.texi | |||
| @@ -70,6 +70,7 @@ developing GNU and promoting software freedom.'' | |||
| 70 | * Efficiency Concerns:: Hints and techniques. | 70 | * Efficiency Concerns:: Hints and techniques. |
| 71 | * Common Lisp Compatibility:: All known differences with Steele. | 71 | * Common Lisp Compatibility:: All known differences with Steele. |
| 72 | * Porting Common Lisp:: Hints for porting Common Lisp code. | 72 | * Porting Common Lisp:: Hints for porting Common Lisp code. |
| 73 | * Obsolete Features:: Obsolete features. | ||
| 73 | 74 | ||
| 74 | * GNU Free Documentation License:: The license for this documentation. | 75 | * GNU Free Documentation License:: The license for this documentation. |
| 75 | * Function Index:: | 76 | * Function Index:: |
| @@ -210,7 +211,6 @@ Internal function and variable names in the package are prefixed | |||
| 210 | by @code{cl--}. Here is a complete list of functions prefixed by | 211 | by @code{cl--}. Here is a complete list of functions prefixed by |
| 211 | @code{cl-} that were not taken from Common Lisp: | 212 | @code{cl-} that were not taken from Common Lisp: |
| 212 | 213 | ||
| 213 | @c FIXME lexical-let lexical-let* | ||
| 214 | @example | 214 | @example |
| 215 | cl-callf cl-callf2 cl-defsubst | 215 | cl-callf cl-callf2 cl-defsubst |
| 216 | cl-floatp-safe cl-letf cl-letf* | 216 | cl-floatp-safe cl-letf cl-letf* |
| @@ -806,12 +806,11 @@ standard @code{setf} facility, and a number of looping and conditional | |||
| 806 | constructs. | 806 | constructs. |
| 807 | 807 | ||
| 808 | @c FIXME | 808 | @c FIXME |
| 809 | @c lexical-let is obsolete; flet is not cl-flet. | 809 | @c flet is not cl-flet, values is not cl-values. |
| 810 | @c values is not cl-values. | ||
| 811 | @menu | 810 | @menu |
| 812 | * Assignment:: The @code{cl-psetq} form. | 811 | * Assignment:: The @code{cl-psetq} form. |
| 813 | * Generalized Variables:: Extensions to generalized variables. | 812 | * Generalized Variables:: Extensions to generalized variables. |
| 814 | * Variable Bindings:: @code{cl-progv}, @code{lexical-let}, @code{flet}, @code{cl-macrolet}. | 813 | * Variable Bindings:: @code{cl-progv}, @code{flet}, @code{cl-macrolet}. |
| 815 | * Conditionals:: @code{cl-case}, @code{cl-typecase}. | 814 | * Conditionals:: @code{cl-case}, @code{cl-typecase}. |
| 816 | * Blocks and Exits:: @code{cl-block}, @code{cl-return}, @code{cl-return-from}. | 815 | * Blocks and Exits:: @code{cl-block}, @code{cl-return}, @code{cl-return-from}. |
| 817 | * Iteration:: @code{cl-do}, @code{cl-dotimes}, @code{cl-dolist}, @code{cl-do-symbols}. | 816 | * Iteration:: @code{cl-do}, @code{cl-dotimes}, @code{cl-dolist}, @code{cl-do-symbols}. |
| @@ -1422,7 +1421,6 @@ are also related to variable bindings. | |||
| 1422 | 1421 | ||
| 1423 | @menu | 1422 | @menu |
| 1424 | * Dynamic Bindings:: The @code{cl-progv} form. | 1423 | * Dynamic Bindings:: The @code{cl-progv} form. |
| 1425 | * Lexical Bindings:: @code{lexical-let} and lexical closures. | ||
| 1426 | * Function Bindings:: @code{flet} and @code{labels}. | 1424 | * Function Bindings:: @code{flet} and @code{labels}. |
| 1427 | * Macro Bindings:: @code{cl-macrolet} and @code{cl-symbol-macrolet}. | 1425 | * Macro Bindings:: @code{cl-macrolet} and @code{cl-symbol-macrolet}. |
| 1428 | @end menu | 1426 | @end menu |
| @@ -1447,120 +1445,6 @@ If @var{symbols} is shorter than @var{values}, the excess values | |||
| 1447 | are ignored. | 1445 | are ignored. |
| 1448 | @end defmac | 1446 | @end defmac |
| 1449 | 1447 | ||
| 1450 | @node Lexical Bindings | ||
| 1451 | @subsection Lexical Bindings | ||
| 1452 | |||
| 1453 | @noindent | ||
| 1454 | The @code{CL} package defines the following macro which | ||
| 1455 | more closely follows the Common Lisp @code{let} form: | ||
| 1456 | |||
| 1457 | @defmac lexical-let (bindings@dots{}) forms@dots{} | ||
| 1458 | This form is exactly like @code{let} except that the bindings it | ||
| 1459 | establishes are purely lexical. Lexical bindings are similar to | ||
| 1460 | local variables in a language like C: Only the code physically | ||
| 1461 | within the body of the @code{lexical-let} (after macro expansion) | ||
| 1462 | may refer to the bound variables. | ||
| 1463 | |||
| 1464 | @example | ||
| 1465 | (setq a 5) | ||
| 1466 | (defun foo (b) (+ a b)) | ||
| 1467 | (let ((a 2)) (foo a)) | ||
| 1468 | @result{} 4 | ||
| 1469 | (lexical-let ((a 2)) (foo a)) | ||
| 1470 | @result{} 7 | ||
| 1471 | @end example | ||
| 1472 | |||
| 1473 | @noindent | ||
| 1474 | In this example, a regular @code{let} binding of @code{a} actually | ||
| 1475 | makes a temporary change to the global variable @code{a}, so @code{foo} | ||
| 1476 | is able to see the binding of @code{a} to 2. But @code{lexical-let} | ||
| 1477 | actually creates a distinct local variable @code{a} for use within its | ||
| 1478 | body, without any effect on the global variable of the same name. | ||
| 1479 | |||
| 1480 | The most important use of lexical bindings is to create @dfn{closures}. | ||
| 1481 | A closure is a function object that refers to an outside lexical | ||
| 1482 | variable. For example: | ||
| 1483 | |||
| 1484 | @example | ||
| 1485 | (defun make-adder (n) | ||
| 1486 | (lexical-let ((n n)) | ||
| 1487 | (function (lambda (m) (+ n m))))) | ||
| 1488 | (setq add17 (make-adder 17)) | ||
| 1489 | (funcall add17 4) | ||
| 1490 | @result{} 21 | ||
| 1491 | @end example | ||
| 1492 | |||
| 1493 | @noindent | ||
| 1494 | The call @code{(make-adder 17)} returns a function object which adds | ||
| 1495 | 17 to its argument. If @code{let} had been used instead of | ||
| 1496 | @code{lexical-let}, the function object would have referred to the | ||
| 1497 | global @code{n}, which would have been bound to 17 only during the | ||
| 1498 | call to @code{make-adder} itself. | ||
| 1499 | |||
| 1500 | @example | ||
| 1501 | (defun make-counter () | ||
| 1502 | (lexical-let ((n 0)) | ||
| 1503 | (cl-function (lambda (&optional (m 1)) (cl-incf n m))))) | ||
| 1504 | (setq count-1 (make-counter)) | ||
| 1505 | (funcall count-1 3) | ||
| 1506 | @result{} 3 | ||
| 1507 | (funcall count-1 14) | ||
| 1508 | @result{} 17 | ||
| 1509 | (setq count-2 (make-counter)) | ||
| 1510 | (funcall count-2 5) | ||
| 1511 | @result{} 5 | ||
| 1512 | (funcall count-1 2) | ||
| 1513 | @result{} 19 | ||
| 1514 | (funcall count-2) | ||
| 1515 | @result{} 6 | ||
| 1516 | @end example | ||
| 1517 | |||
| 1518 | @noindent | ||
| 1519 | Here we see that each call to @code{make-counter} creates a distinct | ||
| 1520 | local variable @code{n}, which serves as a private counter for the | ||
| 1521 | function object that is returned. | ||
| 1522 | |||
| 1523 | Closed-over lexical variables persist until the last reference to | ||
| 1524 | them goes away, just like all other Lisp objects. For example, | ||
| 1525 | @code{count-2} refers to a function object which refers to an | ||
| 1526 | instance of the variable @code{n}; this is the only reference | ||
| 1527 | to that variable, so after @code{(setq count-2 nil)} the garbage | ||
| 1528 | collector would be able to delete this instance of @code{n}. | ||
| 1529 | Of course, if a @code{lexical-let} does not actually create any | ||
| 1530 | closures, then the lexical variables are free as soon as the | ||
| 1531 | @code{lexical-let} returns. | ||
| 1532 | |||
| 1533 | Many closures are used only during the extent of the bindings they | ||
| 1534 | refer to; these are known as ``downward funargs'' in Lisp parlance. | ||
| 1535 | When a closure is used in this way, regular Emacs Lisp dynamic | ||
| 1536 | bindings suffice and will be more efficient than @code{lexical-let} | ||
| 1537 | closures: | ||
| 1538 | |||
| 1539 | @example | ||
| 1540 | (defun add-to-list (x list) | ||
| 1541 | (mapcar (lambda (y) (+ x y))) list) | ||
| 1542 | (add-to-list 7 '(1 2 5)) | ||
| 1543 | @result{} (8 9 12) | ||
| 1544 | @end example | ||
| 1545 | |||
| 1546 | @noindent | ||
| 1547 | Since this lambda is only used while @code{x} is still bound, | ||
| 1548 | it is not necessary to make a true closure out of it. | ||
| 1549 | |||
| 1550 | You can use @code{defun} or @code{flet} inside a @code{lexical-let} | ||
| 1551 | to create a named closure. If several closures are created in the | ||
| 1552 | body of a single @code{lexical-let}, they all close over the same | ||
| 1553 | instance of the lexical variable. | ||
| 1554 | |||
| 1555 | The @code{lexical-let} form is an extension to Common Lisp. In | ||
| 1556 | true Common Lisp, all bindings are lexical unless declared otherwise. | ||
| 1557 | @end defmac | ||
| 1558 | |||
| 1559 | @defmac lexical-let* (bindings@dots{}) forms@dots{} | ||
| 1560 | This form is just like @code{lexical-let}, except that the bindings | ||
| 1561 | are made sequentially in the manner of @code{let*}. | ||
| 1562 | @end defmac | ||
| 1563 | |||
| 1564 | @node Function Bindings | 1448 | @node Function Bindings |
| 1565 | @subsection Function Bindings | 1449 | @subsection Function Bindings |
| 1566 | 1450 | ||
| @@ -1650,6 +1534,10 @@ arguments to @code{cl-defmacro} (i.e., a macro name, argument list, | |||
| 1650 | and macro-expander forms). The macro is defined accordingly for | 1534 | and macro-expander forms). The macro is defined accordingly for |
| 1651 | use within the body of the @code{cl-macrolet}. | 1535 | use within the body of the @code{cl-macrolet}. |
| 1652 | 1536 | ||
| 1537 | @c FIXME this should be modified to say ``even when lexical-binding | ||
| 1538 | @c is code{nil}'', but is that true? The doc of cl-macrolet just | ||
| 1539 | @c refers us to cl-flet, which refers to cl-labels, which says that it | ||
| 1540 | @c behaves differently according to whether l-b is true or not. | ||
| 1653 | Because of the nature of macros, @code{cl-macrolet} is lexically | 1541 | Because of the nature of macros, @code{cl-macrolet} is lexically |
| 1654 | scoped even in Emacs Lisp: The @code{cl-macrolet} binding will | 1542 | scoped even in Emacs Lisp: The @code{cl-macrolet} binding will |
| 1655 | affect only calls that appear physically within the body | 1543 | affect only calls that appear physically within the body |
| @@ -1678,8 +1566,10 @@ I.e., @code{(setq foo 4)} in the above would be equivalent to | |||
| 1678 | 1566 | ||
| 1679 | Likewise, a @code{let} or @code{let*} binding a symbol macro is | 1567 | Likewise, a @code{let} or @code{let*} binding a symbol macro is |
| 1680 | treated like a @code{letf} or @code{cl-letf*}. This differs from true | 1568 | treated like a @code{letf} or @code{cl-letf*}. This differs from true |
| 1569 | @c FIXME does it work like this in Emacs with lexical-binding = t? | ||
| 1681 | Common Lisp, where the rules of lexical scoping cause a @code{let} | 1570 | Common Lisp, where the rules of lexical scoping cause a @code{let} |
| 1682 | binding to shadow a @code{cl-symbol-macrolet} binding. In this package, | 1571 | binding to shadow a @code{cl-symbol-macrolet} binding. In this package, |
| 1572 | @c FIXME obsolete. | ||
| 1683 | only @code{lexical-let} and @code{lexical-let*} will shadow a symbol | 1573 | only @code{lexical-let} and @code{lexical-let*} will shadow a symbol |
| 1684 | macro. | 1574 | macro. |
| 1685 | 1575 | ||
| @@ -4861,19 +4751,15 @@ this convention, calls to Lisp builtins like @code{if} and | |||
| 4861 | 4751 | ||
| 4862 | @item | 4752 | @item |
| 4863 | Lexical scoping. In Common Lisp, function arguments and @code{let} | 4753 | Lexical scoping. In Common Lisp, function arguments and @code{let} |
| 4864 | bindings apply only to references physically within their bodies | 4754 | bindings apply only to references physically within their bodies (or |
| 4865 | (or within macro expansions in their bodies). Emacs Lisp, by | 4755 | within macro expansions in their bodies). Traditionally, Emacs Lisp |
| 4866 | contrast, uses @dfn{dynamic scoping} wherein a binding to a | 4756 | uses @dfn{dynamic scoping} wherein a binding to a variable is visible |
| 4867 | variable is visible even inside functions called from the body. | 4757 | even inside functions called from the body. Lexical binding is |
| 4868 | 4758 | available since Emacs 24.1, so be sure to set @code{lexical-binding} | |
| 4869 | Variables in Common Lisp can be made dynamically scoped by | 4759 | to @code{t} if you need to emulate this aspect of Common Lisp. |
| 4870 | declaring them @code{special} or using @code{defvar}. In Emacs | ||
| 4871 | Lisp it is as if all variables were declared @code{special}. | ||
| 4872 | 4760 | ||
| 4873 | Often you can use code that was written for lexical scoping | 4761 | Here is an example of a Common Lisp code fragment that would fail in |
| 4874 | even in a dynamically scoped Lisp, but not always. Here is | 4762 | Emacs Lisp if @code{lexical-binding} were set to @code{nil}: |
| 4875 | an example of a Common Lisp code fragment that would fail in | ||
| 4876 | Emacs Lisp: | ||
| 4877 | 4763 | ||
| 4878 | @example | 4764 | @example |
| 4879 | (defun map-odd-elements (func list) | 4765 | (defun map-odd-elements (func list) |
| @@ -4886,20 +4772,16 @@ Emacs Lisp: | |||
| 4886 | @end example | 4772 | @end example |
| 4887 | 4773 | ||
| 4888 | @noindent | 4774 | @noindent |
| 4889 | In Common Lisp, the two functions' usages of @code{x} are completely | 4775 | With lexical binding, the two functions' usages of @code{x} are |
| 4890 | independent. In Emacs Lisp, the binding to @code{x} made by | 4776 | completely independent. With dynamic binding, the binding to @code{x} |
| 4891 | @code{add-odd-elements} will have been hidden by the binding | 4777 | made by @code{add-odd-elements} will have been hidden by the binding |
| 4892 | in @code{map-odd-elements} by the time the @code{(+ a x)} function | 4778 | in @code{map-odd-elements} by the time the @code{(+ a x)} function is |
| 4893 | is called. | 4779 | called. |
| 4894 | 4780 | ||
| 4895 | (This package avoids such problems in its own mapping functions | 4781 | Internally, this package uses lexical binding so that such problems do |
| 4896 | by using names like @code{cl--x} instead of @code{x} internally; | 4782 | not occur. @xref{Lexical Bindings}, for a description of the obsolete |
| 4897 | as long as you don't use this prefix for your own | 4783 | @code{lexical-let} form that emulates a Common Lisp-style lexical |
| 4898 | variables no collision can occur.) | 4784 | binding when dynamic binding is in use. |
| 4899 | |||
| 4900 | @xref{Lexical Bindings}, for a description of the @code{lexical-let} | ||
| 4901 | form which establishes a Common Lisp-style lexical binding, and some | ||
| 4902 | examples of how it differs from Emacs's regular @code{let}. | ||
| 4903 | 4785 | ||
| 4904 | @item | 4786 | @item |
| 4905 | Reader macros. Common Lisp includes a second type of macro that | 4787 | Reader macros. Common Lisp includes a second type of macro that |
| @@ -5039,6 +4921,133 @@ note that the current Emacs Lisp compiler does not optimize tail | |||
| 5039 | recursion. | 4921 | recursion. |
| 5040 | @end itemize | 4922 | @end itemize |
| 5041 | 4923 | ||
| 4924 | @node Obsolete Features | ||
| 4925 | @appendix Obsolete Features | ||
| 4926 | |||
| 4927 | This section describes some features of the package that are obsolete | ||
| 4928 | and should not be used in new code. They are only provided by the old | ||
| 4929 | @file{cl.el} entry point, not by the newer @file{cl-lib.el}. | ||
| 4930 | |||
| 4931 | @menu | ||
| 4932 | * Lexical Bindings:: An approximation of lexical binding. | ||
| 4933 | @end menu | ||
| 4934 | |||
| 4935 | @node Lexical Bindings | ||
| 4936 | @appendixsec Lexical Bindings | ||
| 4937 | |||
| 4938 | The following macros are extensions to Common Lisp, where all bindings | ||
| 4939 | are lexical unless declared otherwise. These features are likewise | ||
| 4940 | obsolete since the introduction of true lexical binding in Emacs 24.1. | ||
| 4941 | |||
| 4942 | @defmac lexical-let (bindings@dots{}) forms@dots{} | ||
| 4943 | This form is exactly like @code{let} except that the bindings it | ||
| 4944 | establishes are purely lexical. | ||
| 4945 | @end defmac | ||
| 4946 | |||
| 4947 | @c FIXME remove this and refer to elisp manual. | ||
| 4948 | @c Maybe merge some stuff from here to there? | ||
| 4949 | @noindent | ||
| 4950 | Lexical bindings are similar to local variables in a language like C: | ||
| 4951 | Only the code physically within the body of the @code{lexical-let} | ||
| 4952 | (after macro expansion) may refer to the bound variables. | ||
| 4953 | |||
| 4954 | @example | ||
| 4955 | (setq a 5) | ||
| 4956 | (defun foo (b) (+ a b)) | ||
| 4957 | (let ((a 2)) (foo a)) | ||
| 4958 | @result{} 4 | ||
| 4959 | (lexical-let ((a 2)) (foo a)) | ||
| 4960 | @result{} 7 | ||
| 4961 | @end example | ||
| 4962 | |||
| 4963 | @noindent | ||
| 4964 | In this example, a regular @code{let} binding of @code{a} actually | ||
| 4965 | makes a temporary change to the global variable @code{a}, so @code{foo} | ||
| 4966 | is able to see the binding of @code{a} to 2. But @code{lexical-let} | ||
| 4967 | actually creates a distinct local variable @code{a} for use within its | ||
| 4968 | body, without any effect on the global variable of the same name. | ||
| 4969 | |||
| 4970 | The most important use of lexical bindings is to create @dfn{closures}. | ||
| 4971 | A closure is a function object that refers to an outside lexical | ||
| 4972 | variable. For example: | ||
| 4973 | |||
| 4974 | @example | ||
| 4975 | (defun make-adder (n) | ||
| 4976 | (lexical-let ((n n)) | ||
| 4977 | (function (lambda (m) (+ n m))))) | ||
| 4978 | (setq add17 (make-adder 17)) | ||
| 4979 | (funcall add17 4) | ||
| 4980 | @result{} 21 | ||
| 4981 | @end example | ||
| 4982 | |||
| 4983 | @noindent | ||
| 4984 | The call @code{(make-adder 17)} returns a function object which adds | ||
| 4985 | 17 to its argument. If @code{let} had been used instead of | ||
| 4986 | @code{lexical-let}, the function object would have referred to the | ||
| 4987 | global @code{n}, which would have been bound to 17 only during the | ||
| 4988 | call to @code{make-adder} itself. | ||
| 4989 | |||
| 4990 | @example | ||
| 4991 | (defun make-counter () | ||
| 4992 | (lexical-let ((n 0)) | ||
| 4993 | (cl-function (lambda (&optional (m 1)) (cl-incf n m))))) | ||
| 4994 | (setq count-1 (make-counter)) | ||
| 4995 | (funcall count-1 3) | ||
| 4996 | @result{} 3 | ||
| 4997 | (funcall count-1 14) | ||
| 4998 | @result{} 17 | ||
| 4999 | (setq count-2 (make-counter)) | ||
| 5000 | (funcall count-2 5) | ||
| 5001 | @result{} 5 | ||
| 5002 | (funcall count-1 2) | ||
| 5003 | @result{} 19 | ||
| 5004 | (funcall count-2) | ||
| 5005 | @result{} 6 | ||
| 5006 | @end example | ||
| 5007 | |||
| 5008 | @noindent | ||
| 5009 | Here we see that each call to @code{make-counter} creates a distinct | ||
| 5010 | local variable @code{n}, which serves as a private counter for the | ||
| 5011 | function object that is returned. | ||
| 5012 | |||
| 5013 | Closed-over lexical variables persist until the last reference to | ||
| 5014 | them goes away, just like all other Lisp objects. For example, | ||
| 5015 | @code{count-2} refers to a function object which refers to an | ||
| 5016 | instance of the variable @code{n}; this is the only reference | ||
| 5017 | to that variable, so after @code{(setq count-2 nil)} the garbage | ||
| 5018 | collector would be able to delete this instance of @code{n}. | ||
| 5019 | Of course, if a @code{lexical-let} does not actually create any | ||
| 5020 | closures, then the lexical variables are free as soon as the | ||
| 5021 | @code{lexical-let} returns. | ||
| 5022 | |||
| 5023 | Many closures are used only during the extent of the bindings they | ||
| 5024 | refer to; these are known as ``downward funargs'' in Lisp parlance. | ||
| 5025 | When a closure is used in this way, regular Emacs Lisp dynamic | ||
| 5026 | bindings suffice and will be more efficient than @code{lexical-let} | ||
| 5027 | closures: | ||
| 5028 | |||
| 5029 | @example | ||
| 5030 | (defun add-to-list (x list) | ||
| 5031 | (mapcar (lambda (y) (+ x y))) list) | ||
| 5032 | (add-to-list 7 '(1 2 5)) | ||
| 5033 | @result{} (8 9 12) | ||
| 5034 | @end example | ||
| 5035 | |||
| 5036 | @noindent | ||
| 5037 | Since this lambda is only used while @code{x} is still bound, | ||
| 5038 | it is not necessary to make a true closure out of it. | ||
| 5039 | |||
| 5040 | You can use @code{defun} or @code{flet} inside a @code{lexical-let} | ||
| 5041 | to create a named closure. If several closures are created in the | ||
| 5042 | body of a single @code{lexical-let}, they all close over the same | ||
| 5043 | instance of the lexical variable. | ||
| 5044 | |||
| 5045 | @defmac lexical-let* (bindings@dots{}) forms@dots{} | ||
| 5046 | This form is just like @code{lexical-let}, except that the bindings | ||
| 5047 | are made sequentially in the manner of @code{let*}. | ||
| 5048 | @end defmac | ||
| 5049 | |||
| 5050 | |||
| 5042 | @node GNU Free Documentation License | 5051 | @node GNU Free Documentation License |
| 5043 | @appendix GNU Free Documentation License | 5052 | @appendix GNU Free Documentation License |
| 5044 | @include doclicense.texi | 5053 | @include doclicense.texi |