aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorGlenn Morris2012-10-31 00:25:18 -0700
committerGlenn Morris2012-10-31 00:25:18 -0700
commit69c1c2e65a5cbf9c26fcdc0920ca806d50440860 (patch)
tree8844868fb46d164ad9af4d13c278e45a98026fcf /doc
parent3618df4590230a7321aea685705eda63bf47116b (diff)
downloademacs-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')
-rw-r--r--doc/misc/ChangeLog7
-rw-r--r--doc/misc/cl.texi107
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 @@
12012-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
12012-10-30 Glenn Morris <rgm@gnu.org> 82012-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
820standard @code{setf} facility, and a number of looping and conditional 820standard @code{setf} facility, and a number of looping and conditional
821constructs. 821constructs.
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.
1275These forms make @code{let}-like bindings to functions instead 1273These forms make @code{let}-like bindings to functions instead
1276of variables. 1274of variables.
1277 1275
1278@defmac flet (bindings@dots{}) forms@dots{} 1276@defmac cl-flet (bindings@dots{}) forms@dots{}
1279This form establishes @code{let}-style bindings on the function 1277This form establishes @code{let}-style bindings on the function
1280cells of symbols rather than on the value cells. Each @var{binding} 1278cells of symbols rather than on the value cells. Each @var{binding}
1281must be a list of the form @samp{(@var{name} @var{arglist} 1279must 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
1283it were a @code{cl-defun} form. The function @var{name} is defined 1281it were a @code{cl-defun} form. The function @var{name} is defined
1284accordingly for the duration of the body of the @code{flet}; then 1282accordingly for the duration of the body of the @code{cl-flet}; then
1285the old function definition, or lack thereof, is restored. 1283the old function definition, or lack thereof, is restored.
1286 1284
1287While @code{flet} in Common Lisp establishes a lexical binding of 1285You 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
1289result is that @code{flet} affects indirect calls to a function as
1290well as calls directly inside the @code{flet} form itself.
1291
1292You can use @code{flet} to disable or modify the behavior of a
1293function in a temporary fashion. This will even work on Emacs 1286function in a temporary fashion. This will even work on Emacs
1294primitives, although note that some calls to primitive functions 1287primitives, although note that some calls to primitive functions
1295internal to Emacs are made without going through the symbol's 1288internal to Emacs are made without going through the symbol's
1296function cell, and so will not be affected by @code{flet}. For 1289function cell, and so will not be affected by @code{cl-flet}. For
1297example, 1290example,
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
1304This code attempts to replace the built-in function @code{message} 1297This 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
1310direct C-language calls to the message routines rather than going 1303direct C-language calls to the message routines rather than going
1311through the Lisp @code{message} function. 1304through the Lisp @code{message} function.
1312 1305
1313@c Bug#411. 1306Functions defined by @code{cl-flet} may use the full Common Lisp
1314Also note that many primitives (e.g. @code{+}) have special byte-compile
1315handling. Attempts to redefine such functions using @code{flet} will
1316fail if byte-compiled. In such cases, use @code{labels} instead.
1317
1318Functions defined by @code{flet} may use the full Common Lisp
1319argument notation supported by @code{cl-defun}; also, the function 1307argument notation supported by @code{cl-defun}; also, the function
1320body is enclosed in an implicit block as if by @code{cl-defun}. 1308body 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{}
1325The @code{labels} form is like @code{flet}, except that it 1313The @code{cl-labels} form is like @code{cl-flet}, except that
1326makes lexical bindings of the function names rather than 1314the function bindings can be recursive. The scoping is lexical,
1327dynamic bindings. (In true Common Lisp, both @code{flet} and 1315but 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}.
1329since Emacs Lisp is dynamically bound by default, it seemed 1317@xref{Closures,,,elisp,GNU Emacs Lisp Reference Manual}, and
1330more appropriate for @code{flet} also to use dynamic binding. 1318@ref{Using Lexical Binding,,,elisp,GNU Emacs Lisp Reference Manual}.
1331The @code{labels} form, with its lexical binding, is fully
1332compatible with Common Lisp.)
1333 1319
1334Lexical scoping means that all references to the named 1320Lexical scoping means that all references to the named
1335functions must appear physically within the body of the 1321functions 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
1338the functions themselves. Thus, @code{labels} can define 1324the functions themselves. Thus, @code{cl-labels} can define
1339local recursive functions, or mutually-recursive sets of 1325local recursive functions, or mutually-recursive sets of functions.
1340functions.
1341 1326
1342A ``reference'' to a function name is either a call to that 1327A ``reference'' to a function name is either a call to that
1343function, or a use of its name quoted by @code{quote} or 1328function, 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
1351These forms create local macros and ``symbol macros''. 1336These 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{}
1354This form is analogous to @code{flet}, but for macros instead of 1339This form is analogous to @code{cl-flet}, but for macros instead of
1355functions. Each @var{binding} is a list of the same form as the 1340functions. Each @var{binding} is a list of the same form as the
1356arguments to @code{cl-defmacro} (i.e., a macro name, argument list, 1341arguments to @code{cl-defmacro} (i.e., a macro name, argument list,
1357and macro-expander forms). The macro is defined accordingly for 1342and 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
4598called. 4583called.
4599 4584
4600Internally, this package uses lexical binding so that such problems do 4585Internally, this package uses lexical binding so that such problems do
4601not occur. @xref{Lexical Bindings}, for a description of the obsolete 4586not 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
4603binding when dynamic binding is in use. 4588binding 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
4750in exactly the same way. 4735in 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
4761The following macros are extensions to Common Lisp, where all bindings 4746The following macros are extensions to Common Lisp, where all bindings
4762are lexical unless declared otherwise. These features are likewise 4747are lexical unless declared otherwise. These features are likewise
@@ -4871,21 +4856,43 @@ This form is just like @code{lexical-let}, except that the bindings
4871are made sequentially in the manner of @code{let*}. 4856are 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
4877The following macros are defined using @code{lexical-let}. 4862The following macros are obsolete, and are replaced by versions with
4878They are replaced by versions with a @samp{cl-} prefix that use true 4863a @samp{cl-} prefix that do not behave in exactly the same way.
4879lexical binding (and hence rely on @code{lexical-binding} being set to 4864Consequently, 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{}
4883Replaced by @code{cl-flet} (@pxref{Function Bindings}) 4868This macro is replaced by @code{cl-flet} (@pxref{Function Bindings}),
4884or @code{cl-letf} (@pxref{Modify Macros}). 4869which behaves the same way as Common Lisp's @code{flet}.
4870This @code{flet} takes the same arguments as @code{cl-flet}, but does
4871not behave in precisely the same way.
4872
4873While @code{flet} in Common Lisp establishes a lexical function
4874binding, this @code{flet} makes a dynamic binding (it dates from a
4875time before Emacs had lexical binding). The result is
4876that @code{flet} affects indirect calls to a function as well as calls
4877directly inside the @code{flet} form itself.
4878
4879@c Bug#411.
4880Note that many primitives (e.g. @code{+}) have special byte-compile
4881handling. Attempts to redefine such functions using @code{flet} will
4882fail 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{}
4888Replaced by @code{cl-labels} (@pxref{Function Bindings}). 4888This macro is replaced by @code{cl-labels} (@pxref{Function Bindings}),
4889which behaves the same way as Common Lisp's @code{labels}.
4890This @code{labels} takes the same arguments as @code{cl-labels}, but
4891does not behave in precisely the same way.
4892
4893This version of @code{labels} uses the obsolete @code{lexical-let}
4894form (@pxref{Obsolete Lexical Binding}), rather than the true
4895lexical 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{}