help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: flet + advised functions


From: PJ Weisberg
Subject: Re: flet + advised functions
Date: Tue, 8 Mar 2011 11:38:47 -0800

On Mon, Mar 7, 2011 at 10:47 PM, Andreas Politz <address@hidden> wrote:
>
> I just discovered that `flet' does not work with (some form of)
> advised functions, such that it doesn't restore the original
> function.  I have found no references to this behaviour on the
> net, no bug reports either.  The results are the same in
> emacs22/24. I assume, it has been this way for a long time !?
>
> (progn
>  (unintern 'foo)
>  (defun foo () 'defun)
>  (defadvice foo (around foo activate)
>    ad-do-it)
>  (setq letf-save (symbol-function
>                   ;;'ad-Orig-foo
>                   'foo
>                   ))
>  (fset 'foo (lambda nil 'flet))
>  (fset 'foo letf-save)
>  (foo))
>
> => flet
>
> -ap
>

This belongs in a bug-report, not on the help mailing list.

It looks like the problem is with symbol-function, not flet (since you
never actually use flet in the example).

'(unintern foo)' is also unnecessary; I'd remove it to avoid muddying
the waters.

(progn
 (defun foo () 'defun)
 (defadvice foo (around foo activate)
   ad-do-it)
 (setq letf-save (symbol-function
                  'foo
                  ))
 (fset 'foo (lambda nil 'fset))
 (fset 'foo letf-save)
 (foo))
=> fset

(symbol-function 'foo)
=> #[nil "\301\302 \211)\207" [ad-return-value nil ad-Orig-foo] 2
#("Advice doc string" 0 17 (ad-advice-info foo))]

I see  that the byte-compiled result of symbol-function doesn't
contain the symbol that it's supposed to return, but an un-advised
version does.

(progn
 (defun foo () 'defun)
 (setq letf-save (symbol-function
                  'foo
                  ))
 (fset 'foo (lambda nil 'fset))
 (fset 'foo letf-save)
 (byte-compile 'foo)
 (symbol-function 'foo))

=> #[nil "\300\207" [defun] 1]

-PJ



reply via email to

[Prev in Thread] Current Thread [Next in Thread]