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: tomas
Subject: Re: Question about cl-flet and cl-letf
Date: Sun, 29 Oct 2023 07:19:40 +0100

On Sun, Oct 29, 2023 at 02:14:10AM +0200, Michael Heerdegen wrote:
> Arash Esbati <arash@gnu.org> writes:
> 
> > Michael Heerdegen <michael_heerdegen@web.de> writes:
> >
> > > 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.
> >
> > Thanks for your response.  I basically want to temporarily make
> > `y-or-n-p' act like `always'; and from what I read in the docstrings,
> > both version should work, but `cl-flet' does not.  Are the bindings
> > relevant in this case?
> 
> Yes.  Please read about scoping rules:
> 
>   (info "(elisp) Variable Scoping")
> 
> the analogue rules apply for function bindings.
> 
> When the call of `y-or-n-p' does not occur textually inside the
> `cl-flet' form, it will not be affected by a lexical function binding.

It can be confusing. Look at it this way: y-or-no-p is most probably
not called directly in your (while ...) construct (which is a
special form) but from some functions called from there.

So it's not in your lexical environment, but on somewhere else's.
So a dynamic binding does the trick.

Cheers
-- 
t

Attachment: signature.asc
Description: PGP signature


reply via email to

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