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

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

Re: Question about cl-flet and cl-letf


From: Michael Heerdegen
Subject: Re: Question about cl-flet and cl-letf
Date: Thu, 26 Oct 2023 23:53:09 +0200
User-agent: Gnus/5.13 (Gnus v5.13)

Arash Esbati <arash@gnu.org> writes:

> Hi all,
>
> my understanding of the manual and docstring of the macros mentioned
> above is that these two pieces of code should be equivalent:
>
>   (cl-flet ((y-or-n-p #'always))
>     (while (...)
>       BODY))
>
>   (cl-letf (((symbol-function 'y-or-n-p) #'always))
>     (while (...)
>       BODY))
>
> I have an use-case where they are not.  Before getting into details
> about the function (which is long) and trying to come up with a reduced
> version: Am I correct with the assumption above?

No - they very different.  `cl-flet' creates lexical bindings.  Your
`cl-letf' call OTOH temporarily changes the function binding of the
symbol `y-or-n-p' - which more or less gives you dynamical binding.

Michael.




reply via email to

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