[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to shadow a function temporarily? (flet and cl-flet)
From: |
Barry Margolin |
Subject: |
Re: How to shadow a function temporarily? (flet and cl-flet) |
Date: |
Sun, 26 Jan 2014 14:36:21 -0500 |
User-agent: |
MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) |
In article <mailman.12843.1390745495.10748.help-gnu-emacs@gnu.org>,
Alex Kost <alezost@gmail.com> wrote:
> Hello, I have 2 questions.
>
> 1. The main question is: how can I override a function with another
> compatible function (with the same args) temporarily?
>
> I want something like this:
>
> (let-shadow ((+ '-))
> (+ 3 2)) ; should return 1, not 5
>
> 2. If there is no such macro, I can use `flet' for my purposes, but it
> is obsolete and `cl-flet' doesn't do what I need (see attached example).
>
> According to (info "(cl) Obsolete Macros"), `flet' makes a dynamic
> binding (unlike `cl-flet'). So the second question is: how can I avoid
> using obsolete `flet` if I need a dynamic binding?
Use `letf' of `symbol-function':
(letf ((symbol-function 'function-name) (symbol-function
'other-function))
...)
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
- Re: How to shadow a function temporarily? (flet and cl-flet), (continued)
Re: How to shadow a function temporarily? (flet and cl-flet), Marcin Borkowski, 2014/01/26
Re: How to shadow a function temporarily? (flet and cl-flet), Emanuel Berg, 2014/01/26
Re: How to shadow a function temporarily? (flet and cl-flet), Emanuel Berg, 2014/01/26
Re: How to shadow a function temporarily? (flet and cl-flet),
Barry Margolin <=