[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to shadow a function temporarily? (flet and cl-flet)
From: |
Alex Kost |
Subject: |
Re: How to shadow a function temporarily? (flet and cl-flet) |
Date: |
Sun, 26 Jan 2014 23:24:44 +0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
Stefan Monnier (2014-01-26 18:50 +0400) wrote:
>> 1. The main question is: how can I override a function with another
>> compatible function (with the same args) temporarily?
>
> Be careful with "temporarily": it can be interpreted as "lexically" or
> "dynamically". From your example, it seems you want "dynamically".
> Note, tho, that
>
> (defun 8+ (arg)
> (+ 8 arg))
>
> (flet ((+ (&rest args)
> (apply '- args)))
> (8+ 3)) ; => 5
>
> will give you 11 when byte-compiled.
Thank you, I didn't know about that.
> IOW, you had better look for
> another solution to your problem. One option could be something along
> the following lines:
>
> (defvar my-plus-is-subtraction nil)
>
> (defun 8+ (arg)
> (funcall (if my-plus-is-subtraction #'- #'+) 8 arg))
>
> (let ((my-plus-is-subtraction t))
> (8+ 3)) ; => 5
It was an example, I cannot modify `8+' function.
Here is what I actiually need: I want to make `read-color' function to
use my functions instead of `foreground-color-at-point' and
`background-color-at-point', so I tried the following (but now I see
that it's not suitable):
binmT2KlAv1lO.bin
Description: application/emacs-lisp
Now i don't see another solution except of using the code of
`read-color' in `my-read-color'.
Re: How to shadow a function temporarily? (flet and cl-flet), Marcin Borkowski, 2014/01/26