GNU bug report logs - #14293
23.4; Unclarity in documentation: flet replaced by cl-flet of cl-letf in 24.3 and up.

Previous Next

Package: emacs;

Reported by: Nikolaus Demmel <nikolaus <at> nikolaus-demmel.de>

Date: Sat, 27 Apr 2013 18:00:02 UTC

Severity: minor

Found in version 23.4

Done: Stefan Monnier <monnier <at> IRO.UMontreal.CA>

Bug is archived. No further changes may be made.

Full log


Message #10 received at 14293-done <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: Nikolaus Demmel <nikolaus <at> nikolaus-demmel.de>
Cc: 14293-done <at> debbugs.gnu.org
Subject: Re: 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
> 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





This bug report was last modified 12 years and 25 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.