diff options
| author | Glenn Morris | 2012-10-31 00:25:18 -0700 |
|---|---|---|
| committer | Glenn Morris | 2012-10-31 00:25:18 -0700 |
| commit | 69c1c2e65a5cbf9c26fcdc0920ca806d50440860 (patch) | |
| tree | 8844868fb46d164ad9af4d13c278e45a98026fcf /doc/misc | |
| parent | 3618df4590230a7321aea685705eda63bf47116b (diff) | |
| download | emacs-69c1c2e65a5cbf9c26fcdc0920ca806d50440860.tar.gz emacs-69c1c2e65a5cbf9c26fcdc0920ca806d50440860.zip | |
Document cl-flet and cl-labels in doc/misc/cl.texi
* doc/misc/cl.texi (Function Bindings): Update for cl-flet and cl-labels.
(Obsolete Lexical Binding): Rename section from "Lexical Bindings".
(Obsolete Macros): Rename section from "Obsolete Lexical Macros".
Reword, and add details of flet and labels.
* etc/NEWS: Related markup.
Diffstat (limited to 'doc/misc')
| -rw-r--r-- | doc/misc/ChangeLog | 7 | ||||
| -rw-r--r-- | doc/misc/cl.texi | 107 |
2 files changed, 64 insertions, 50 deletions
diff --git a/doc/misc/ChangeLog b/doc/misc/ChangeLog index 941c430ce74..11fe77ea471 100644 --- a/doc/misc/ChangeLog +++ b/doc/misc/ChangeLog | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | 2012-10-31 Glenn Morris <rgm@gnu.org> | ||
| 2 | |||
| 3 | * cl.texi (Function Bindings): Update for cl-flet and cl-labels. | ||
| 4 | (Obsolete Lexical Binding): Rename section from "Lexical Bindings". | ||
| 5 | (Obsolete Macros): Rename section from "Obsolete Lexical Macros". | ||
| 6 | Reword, and add details of flet and labels. | ||
| 7 | |||
| 1 | 2012-10-30 Glenn Morris <rgm@gnu.org> | 8 | 2012-10-30 Glenn Morris <rgm@gnu.org> |
| 2 | 9 | ||
| 3 | * cl.texi (Modify Macros): Update for cl-letf changes. | 10 | * cl.texi (Modify Macros): Update for cl-letf changes. |
diff --git a/doc/misc/cl.texi b/doc/misc/cl.texi index 3870eb33064..d01798497da 100644 --- a/doc/misc/cl.texi +++ b/doc/misc/cl.texi | |||
| @@ -820,12 +820,10 @@ various advanced control structures, including extensions to the | |||
| 820 | standard @code{setf} facility, and a number of looping and conditional | 820 | standard @code{setf} facility, and a number of looping and conditional |
| 821 | constructs. | 821 | constructs. |
| 822 | 822 | ||
| 823 | @c FIXME | ||
| 824 | @c flet is not cl-flet. | ||
| 825 | @menu | 823 | @menu |
| 826 | * Assignment:: The @code{cl-psetq} form. | 824 | * Assignment:: The @code{cl-psetq} form. |
| 827 | * Generalized Variables:: Extensions to generalized variables. | 825 | * Generalized Variables:: Extensions to generalized variables. |
| 828 | * Variable Bindings:: @code{cl-progv}, @code{flet}, @code{cl-macrolet}. | 826 | * Variable Bindings:: @code{cl-progv}, @code{cl-flet}, @code{cl-macrolet}. |
| 829 | * Conditionals:: @code{cl-case}, @code{cl-typecase}. | 827 | * Conditionals:: @code{cl-case}, @code{cl-typecase}. |
| 830 | * Blocks and Exits:: @code{cl-block}, @code{cl-return}, @code{cl-return-from}. | 828 | * Blocks and Exits:: @code{cl-block}, @code{cl-return}, @code{cl-return-from}. |
| 831 | * Iteration:: @code{cl-do}, @code{cl-dotimes}, @code{cl-dolist}, @code{cl-do-symbols}. | 829 | * Iteration:: @code{cl-do}, @code{cl-dotimes}, @code{cl-dolist}, @code{cl-do-symbols}. |
| @@ -1244,7 +1242,7 @@ are also related to variable bindings. | |||
| 1244 | 1242 | ||
| 1245 | @menu | 1243 | @menu |
| 1246 | * Dynamic Bindings:: The @code{cl-progv} form. | 1244 | * Dynamic Bindings:: The @code{cl-progv} form. |
| 1247 | * Function Bindings:: @code{flet} and @code{labels}. | 1245 | * Function Bindings:: @code{cl-flet} and @code{cl-labels}. |
| 1248 | * Macro Bindings:: @code{cl-macrolet} and @code{cl-symbol-macrolet}. | 1246 | * Macro Bindings:: @code{cl-macrolet} and @code{cl-symbol-macrolet}. |
| 1249 | @end menu | 1247 | @end menu |
| 1250 | 1248 | ||
| @@ -1275,30 +1273,25 @@ are ignored. | |||
| 1275 | These forms make @code{let}-like bindings to functions instead | 1273 | These forms make @code{let}-like bindings to functions instead |
| 1276 | of variables. | 1274 | of variables. |
| 1277 | 1275 | ||
| 1278 | @defmac flet (bindings@dots{}) forms@dots{} | 1276 | @defmac cl-flet (bindings@dots{}) forms@dots{} |
| 1279 | This form establishes @code{let}-style bindings on the function | 1277 | This form establishes @code{let}-style bindings on the function |
| 1280 | cells of symbols rather than on the value cells. Each @var{binding} | 1278 | cells of symbols rather than on the value cells. Each @var{binding} |
| 1281 | must be a list of the form @samp{(@var{name} @var{arglist} | 1279 | must be a list of the form @samp{(@var{name} @var{arglist} |
| 1282 | @var{forms}@dots{})}, which defines a function exactly as if | 1280 | @var{forms}@dots{})}, which defines a function exactly as if |
| 1283 | it were a @code{cl-defun} form. The function @var{name} is defined | 1281 | it were a @code{cl-defun} form. The function @var{name} is defined |
| 1284 | accordingly for the duration of the body of the @code{flet}; then | 1282 | accordingly for the duration of the body of the @code{cl-flet}; then |
| 1285 | the old function definition, or lack thereof, is restored. | 1283 | the old function definition, or lack thereof, is restored. |
| 1286 | 1284 | ||
| 1287 | While @code{flet} in Common Lisp establishes a lexical binding of | 1285 | You can use @code{cl-flet} to disable or modify the behavior of a |
| 1288 | @var{name}, Emacs Lisp @code{flet} makes a dynamic binding. The | ||
| 1289 | result is that @code{flet} affects indirect calls to a function as | ||
| 1290 | well as calls directly inside the @code{flet} form itself. | ||
| 1291 | |||
| 1292 | You can use @code{flet} to disable or modify the behavior of a | ||
| 1293 | function in a temporary fashion. This will even work on Emacs | 1286 | function in a temporary fashion. This will even work on Emacs |
| 1294 | primitives, although note that some calls to primitive functions | 1287 | primitives, although note that some calls to primitive functions |
| 1295 | internal to Emacs are made without going through the symbol's | 1288 | internal to Emacs are made without going through the symbol's |
| 1296 | function cell, and so will not be affected by @code{flet}. For | 1289 | function cell, and so will not be affected by @code{cl-flet}. For |
| 1297 | example, | 1290 | example, |
| 1298 | 1291 | ||
| 1299 | @example | 1292 | @example |
| 1300 | (flet ((message (&rest args) (push args saved-msgs))) | 1293 | (cl-flet ((message (&rest args) (push args saved-msgs))) |
| 1301 | (do-something)) | 1294 | (do-something)) |
| 1302 | @end example | 1295 | @end example |
| 1303 | 1296 | ||
| 1304 | This code attempts to replace the built-in function @code{message} | 1297 | This code attempts to replace the built-in function @code{message} |
| @@ -1310,34 +1303,26 @@ generated directly inside Emacs will not be caught since they make | |||
| 1310 | direct C-language calls to the message routines rather than going | 1303 | direct C-language calls to the message routines rather than going |
| 1311 | through the Lisp @code{message} function. | 1304 | through the Lisp @code{message} function. |
| 1312 | 1305 | ||
| 1313 | @c Bug#411. | 1306 | Functions defined by @code{cl-flet} may use the full Common Lisp |
| 1314 | Also note that many primitives (e.g. @code{+}) have special byte-compile | ||
| 1315 | handling. Attempts to redefine such functions using @code{flet} will | ||
| 1316 | fail if byte-compiled. In such cases, use @code{labels} instead. | ||
| 1317 | |||
| 1318 | Functions defined by @code{flet} may use the full Common Lisp | ||
| 1319 | argument notation supported by @code{cl-defun}; also, the function | 1307 | argument notation supported by @code{cl-defun}; also, the function |
| 1320 | body is enclosed in an implicit block as if by @code{cl-defun}. | 1308 | body is enclosed in an implicit block as if by @code{cl-defun}. |
| 1321 | @xref{Program Structure}. | 1309 | @xref{Program Structure}. |
| 1322 | @end defmac | 1310 | @end defmac |
| 1323 | 1311 | ||
| 1324 | @defmac labels (bindings@dots{}) forms@dots{} | 1312 | @defmac cl-labels (bindings@dots{}) forms@dots{} |
| 1325 | The @code{labels} form is like @code{flet}, except that it | 1313 | The @code{cl-labels} form is like @code{cl-flet}, except that |
| 1326 | makes lexical bindings of the function names rather than | 1314 | the function bindings can be recursive. The scoping is lexical, |
| 1327 | dynamic bindings. (In true Common Lisp, both @code{flet} and | 1315 | but you can only capture functions in closures if |
| 1328 | @code{labels} make lexical bindings of slightly different sorts; | 1316 | @code{lexical-binding} is non-@code{nil}. |
| 1329 | since Emacs Lisp is dynamically bound by default, it seemed | 1317 | @xref{Closures,,,elisp,GNU Emacs Lisp Reference Manual}, and |
| 1330 | more appropriate for @code{flet} also to use dynamic binding. | 1318 | @ref{Using Lexical Binding,,,elisp,GNU Emacs Lisp Reference Manual}. |
| 1331 | The @code{labels} form, with its lexical binding, is fully | ||
| 1332 | compatible with Common Lisp.) | ||
| 1333 | 1319 | ||
| 1334 | Lexical scoping means that all references to the named | 1320 | Lexical scoping means that all references to the named |
| 1335 | functions must appear physically within the body of the | 1321 | functions must appear physically within the body of the |
| 1336 | @code{labels} form. References may appear both in the body | 1322 | @code{cl-labels} form. References may appear both in the body |
| 1337 | @var{forms} of @code{labels} itself, and in the bodies of | 1323 | @var{forms} of @code{cl-labels} itself, and in the bodies of |
| 1338 | the functions themselves. Thus, @code{labels} can define | 1324 | the functions themselves. Thus, @code{cl-labels} can define |
| 1339 | local recursive functions, or mutually-recursive sets of | 1325 | local recursive functions, or mutually-recursive sets of functions. |
| 1340 | functions. | ||
| 1341 | 1326 | ||
| 1342 | A ``reference'' to a function name is either a call to that | 1327 | A ``reference'' to a function name is either a call to that |
| 1343 | function, or a use of its name quoted by @code{quote} or | 1328 | function, or a use of its name quoted by @code{quote} or |
| @@ -1351,7 +1336,7 @@ function, or a use of its name quoted by @code{quote} or | |||
| 1351 | These forms create local macros and ``symbol macros''. | 1336 | These forms create local macros and ``symbol macros''. |
| 1352 | 1337 | ||
| 1353 | @defmac cl-macrolet (bindings@dots{}) forms@dots{} | 1338 | @defmac cl-macrolet (bindings@dots{}) forms@dots{} |
| 1354 | This form is analogous to @code{flet}, but for macros instead of | 1339 | This form is analogous to @code{cl-flet}, but for macros instead of |
| 1355 | functions. Each @var{binding} is a list of the same form as the | 1340 | functions. Each @var{binding} is a list of the same form as the |
| 1356 | arguments to @code{cl-defmacro} (i.e., a macro name, argument list, | 1341 | arguments to @code{cl-defmacro} (i.e., a macro name, argument list, |
| 1357 | and macro-expander forms). The macro is defined accordingly for | 1342 | and macro-expander forms). The macro is defined accordingly for |
| @@ -4598,7 +4583,7 @@ in @code{map-odd-elements} by the time the @code{(+ a x)} function is | |||
| 4598 | called. | 4583 | called. |
| 4599 | 4584 | ||
| 4600 | Internally, this package uses lexical binding so that such problems do | 4585 | Internally, this package uses lexical binding so that such problems do |
| 4601 | not occur. @xref{Lexical Bindings}, for a description of the obsolete | 4586 | not occur. @xref{Obsolete Lexical Binding}, for a description of the obsolete |
| 4602 | @code{lexical-let} form that emulates a Common Lisp-style lexical | 4587 | @code{lexical-let} form that emulates a Common Lisp-style lexical |
| 4603 | binding when dynamic binding is in use. | 4588 | binding when dynamic binding is in use. |
| 4604 | 4589 | ||
| @@ -4750,13 +4735,13 @@ or where versions with a @samp{cl-} prefix do exist they do not behave | |||
| 4750 | in exactly the same way. | 4735 | in exactly the same way. |
| 4751 | 4736 | ||
| 4752 | @menu | 4737 | @menu |
| 4753 | * Lexical Bindings:: An approximation of lexical binding. | 4738 | * Obsolete Lexical Binding:: An approximation of lexical binding. |
| 4754 | * Obsolete Lexical Macros:: Obsolete macros using lexical-let. | 4739 | * Obsolete Macros:: Obsolete macros. |
| 4755 | * Obsolete Setf Customization:: Obsolete ways to customize setf. | 4740 | * Obsolete Setf Customization:: Obsolete ways to customize setf. |
| 4756 | @end menu | 4741 | @end menu |
| 4757 | 4742 | ||
| 4758 | @node Lexical Bindings | 4743 | @node Obsolete Lexical Binding |
| 4759 | @appendixsec Lexical Bindings | 4744 | @appendixsec Obsolete Lexical Binding |
| 4760 | 4745 | ||
| 4761 | The following macros are extensions to Common Lisp, where all bindings | 4746 | The following macros are extensions to Common Lisp, where all bindings |
| 4762 | are lexical unless declared otherwise. These features are likewise | 4747 | are lexical unless declared otherwise. These features are likewise |
| @@ -4871,21 +4856,43 @@ This form is just like @code{lexical-let}, except that the bindings | |||
| 4871 | are made sequentially in the manner of @code{let*}. | 4856 | are made sequentially in the manner of @code{let*}. |
| 4872 | @end defmac | 4857 | @end defmac |
| 4873 | 4858 | ||
| 4874 | @node Obsolete Lexical Macros | 4859 | @node Obsolete Macros |
| 4875 | @appendixsec Macros Defined Using Lexical-Let | 4860 | @appendixsec Obsolete Macros |
| 4876 | 4861 | ||
| 4877 | The following macros are defined using @code{lexical-let}. | 4862 | The following macros are obsolete, and are replaced by versions with |
| 4878 | They are replaced by versions with a @samp{cl-} prefix that use true | 4863 | a @samp{cl-} prefix that do not behave in exactly the same way. |
| 4879 | lexical binding (and hence rely on @code{lexical-binding} being set to | 4864 | Consequently, the @file{cl.el} versions are not simply aliases to the |
| 4880 | @code{t} in code using them). | 4865 | @file{cl-lib.el} versions. |
| 4881 | 4866 | ||
| 4882 | @defmac flet (bindings@dots{}) forms@dots{} | 4867 | @defmac flet (bindings@dots{}) forms@dots{} |
| 4883 | Replaced by @code{cl-flet} (@pxref{Function Bindings}) | 4868 | This macro is replaced by @code{cl-flet} (@pxref{Function Bindings}), |
| 4884 | or @code{cl-letf} (@pxref{Modify Macros}). | 4869 | which behaves the same way as Common Lisp's @code{flet}. |
| 4870 | This @code{flet} takes the same arguments as @code{cl-flet}, but does | ||
| 4871 | not behave in precisely the same way. | ||
| 4872 | |||
| 4873 | While @code{flet} in Common Lisp establishes a lexical function | ||
| 4874 | binding, this @code{flet} makes a dynamic binding (it dates from a | ||
| 4875 | time before Emacs had lexical binding). The result is | ||
| 4876 | that @code{flet} affects indirect calls to a function as well as calls | ||
| 4877 | directly inside the @code{flet} form itself. | ||
| 4878 | |||
| 4879 | @c Bug#411. | ||
| 4880 | Note that many primitives (e.g. @code{+}) have special byte-compile | ||
| 4881 | handling. Attempts to redefine such functions using @code{flet} will | ||
| 4882 | fail if byte-compiled. | ||
| 4883 | @c Or cl-flet. | ||
| 4884 | @c In such cases, use @code{labels} instead. | ||
| 4885 | @end defmac | 4885 | @end defmac |
| 4886 | 4886 | ||
| 4887 | @defmac labels (bindings@dots{}) forms@dots{} | 4887 | @defmac labels (bindings@dots{}) forms@dots{} |
| 4888 | Replaced by @code{cl-labels} (@pxref{Function Bindings}). | 4888 | This macro is replaced by @code{cl-labels} (@pxref{Function Bindings}), |
| 4889 | which behaves the same way as Common Lisp's @code{labels}. | ||
| 4890 | This @code{labels} takes the same arguments as @code{cl-labels}, but | ||
| 4891 | does not behave in precisely the same way. | ||
| 4892 | |||
| 4893 | This version of @code{labels} uses the obsolete @code{lexical-let} | ||
| 4894 | form (@pxref{Obsolete Lexical Binding}), rather than the true | ||
| 4895 | lexical binding that @code{cl-labels} uses. | ||
| 4889 | @end defmac | 4896 | @end defmac |
| 4890 | 4897 | ||
| 4891 | @defmac letf (bindings@dots{}) forms@dots{} | 4898 | @defmac letf (bindings@dots{}) forms@dots{} |