[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#14293: 23.4; Unclarity in documentation: flet replaced by cl-flet of
From: |
Stefan Monnier |
Subject: |
bug#14293: 23.4; Unclarity in documentation: flet replaced by cl-flet of cl-letf in 24.3 and up. |
Date: |
Sat, 04 May 2013 15:50:24 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) |
> that using defadvice might be more appropriate. Maybe the information
> about how to precisely replace flet (i.e. same call if using cl-flet,
> different syntax if dynamic binding is desired using cl-letf, with an
> hint that defadvice might be better) could be included somewhere in the
> docs, maybe in [2]?
Thanks. I installed the patch below.
Stefan
=== modified file 'doc/misc/cl.texi'
--- doc/misc/cl.texi 2013-02-20 02:07:07 +0000
+++ doc/misc/cl.texi 2013-05-04 19:46:20 +0000
@@ -4850,10 +4850,27 @@
direct C-language calls to the message routines rather than going
through the Lisp @code{message} function.
+For those cases where the dynamic scoping of @code{flet} is desired,
+@code{cl-flet} is clearly not a substitute. The most direct replacement would
+be instead to use @code{cl-letf} to temporarily rebind @code{(symbol-function
+'@var{fun})}. But in most cases, a better substitute is to use an advice, such
+as:
+
+@example
+(defvar my-fun-advice-enable nil)
+(add-advice '@var{fun} :around
+ (lambda (orig &rest args)
+ (if my-fun-advice-enable (do-something)
+ (apply orig args))))
+@end example
+
+so that you can then replace the @code{flet} with a simple dynamically scoped
+binding of @code{my-fun-advice-enable}.
+
@c Bug#411.
Note that many primitives (e.g., @code{+}) have special byte-compile
-handling. Attempts to redefine such functions using @code{flet} will
-fail if byte-compiled.
+handling. Attempts to redefine such functions using @code{flet}, @code{letf},
+or an advice will fail when byte-compiled.
@c Or cl-flet.
@c In such cases, use @code{labels} instead.
@end defmac
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- bug#14293: 23.4; Unclarity in documentation: flet replaced by cl-flet of cl-letf in 24.3 and up.,
Stefan Monnier <=