emacs-devel
[Top][All Lists]
Advanced

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

Sv: Is this a bug in while-let or do I missunderstand it?


From: arthur miller
Subject: Sv: Is this a bug in while-let or do I missunderstand it?
Date: Sat, 9 Nov 2024 14:44:45 +0000

>But if it did it that way, the condition (init-form) would only be
>evaluated once, and I’d find *that* counterintuitive. Consider the

?

I don't know man. Why would it be so? Loops conditions should always be
evaluated in a loop, otherwise how should loop terminate? But I don't
expect a loop to re-initiate all bindings from defaults each time it
runs an iteration. It is both expensive, unnecessary and counterintuitive.
Don't you think?

>usual form of a while loop:
>
>    (while-let ((run (some-condition)))
>      (message "running"))
>
>Do you expect that to evaluate (some-condition) once, then, if it’s
>initially true, run forever?

That usual form of while loop works because (some-condition) is a function,
and it obviously computes its condition based on the external environment.

Perhaps you can set some global value in the loop to stop the evaluation, or
perhaps (some-condition) computes the terminating condition based on some
other volatile values from the environment. I don't see is that in the
conflict to what I say.

If you instead write

(while-let ((run some-condition))
   (message "running"))

Than yes, the loop will not terminate unless you terminate it from the loop.
However, since we are throwing away the bindings on each iteration, we are
also throwing away the previously computed binding, we can't write:

(while-let ((run some-condition))
   (message "running")
   (setf run nil))

Which to me seems counterintuitive.

Från: Yuri Khan <yuri.v.khan@gmail.com>
Skickat: den 9 november 2024 15:04
Till: arthur miller <arthur.miller@live.com>
Kopia: emacs-devel@gnu.org <emacs-devel@gnu.org>
Ämne: Re: Is this a bug in while-let or do I missunderstand it?
 
On Sat, 9 Nov 2024 at 20:47, arthur miller <arthur.miller@live.com> wrote:

> If it wasn't clear, the unintuitive part is that while-let was to
> establish the local environment, so that we don't need to type:
>
> (let ((som-var (init-form)))
>     (while some-var
>         ... ))

But if it did it that way, the condition (init-form) would only be
evaluated once, and I’d find *that* counterintuitive. Consider the
usual form of a while loop:

    (while-let ((run (some-condition)))
      (message "running"))

Do you expect that to evaluate (some-condition) once, then, if it’s
initially true, run forever?

reply via email to

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