unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@IRO.UMontreal.CA>
To: Nikolaus Demmel <nikolaus@nikolaus-demmel.de>
Cc: 14293-done@debbugs.gnu.org
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	[thread overview]
Message-ID: <jwvobcqpltk.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <0174328B-6C51-4143-8FD7-DE02EB82E86D@nikolaus-demmel.de> (Nikolaus Demmel's message of "Sat, 27 Apr 2013 13:37:46 +0200")

> 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






      reply	other threads:[~2013-05-04 19:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-27 11:37 bug#14293: 23.4; Unclarity in documentation: flet replaced by cl-flet of cl-letf in 24.3 and up Nikolaus Demmel
2013-05-04 19:50 ` Stefan Monnier [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvobcqpltk.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=14293-done@debbugs.gnu.org \
    --cc=nikolaus@nikolaus-demmel.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).