[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Is this a bug in while-let or do I missunderstand it?
From: |
Alfred M. Szmidt |
Subject: |
Re: Is this a bug in while-let or do I missunderstand it? |
Date: |
Sun, 10 Nov 2024 07:10:26 -0500 |
@defmac while-let spec then-forms...
Like @code{when-let*}, but repeat until a binding in @var{spec} is
@code{nil}. The return value is always @code{nil}.
The "Like FOO" is confusing -- it is not like when-let*, when-let* is
also not like let*. E.g., when spec is (binding value) or just
(value) (!?) -- which should be mentioned in the manual.
These foo-LET are are mixing up the condition being tested and the
binding, when there is no binding the form seems to be just a test as
if you'd pass it directly to WHEN (or whatever). There should be some
example that SPEC is not at all like in LET, and that:
(when-let* ((result1 (do-computation))
( (do-more result1)))
(do-something result1))
is something like (I guess?):
(let ((result1 (do-computation)))
(when result1
(when (do-more result1)
(do-something result2))))
And these mentions of "Like LET*" should be removed entierly.
But this is a better, and a good start.
@code{while-let} replaces a common pattern in which a binding is
established outside the @{while}-loop, tested as part of the condition of
@{while} and subsequently changed inside the loop using the same expression
that it was originally bound to:
@example
(let ((result (do-computation)))
(while result
(do-stuff-with result)
(setq result (do-computation))))
@end example
Using @code{while-let}, this can be written more succinctly as:
@example
(while-let ((result (do-computation)))
(do-stuff-with result))
@end example
The binding of @code{result} is reestablished at every iteration, therefore
setting the value of @code{result} inside the loop has no effect. In order
to end the loop, @code{(do-computation)} should eventually return
@code{nil}.
This example uses a single binding for clarity, but obviously
@code{while-let} can establish multiple bindings. The loop runs as long as
all bindings are non-@code{nil}.
@end defmac
```
Am I mistaken or is `while-let` a bit like a do..until loop that some
languages offer?
--
Joost Kremers
Life has its moments
- Re: Better documentation for non-binding clauses of if-let and friends, (continued)
- Re: Better documentation for non-binding clauses of if-let and friends, Jens Schmidt, 2024/11/10
- Re: Better documentation for non-binding clauses of if-let and friends, Alfred M. Szmidt, 2024/11/11
- Re: Better documentation for non-binding clauses of if-let and friends, Alfred M. Szmidt, 2024/11/11
- Sv: [External] : Re: Is this a bug in while-let or do I missunderstand it?, arthur miller, 2024/11/10
- RE: [External] : Re: Is this a bug in while-let or do I missunderstand it?, Drew Adams, 2024/11/09
- RE: [External] : Re: Is this a bug in while-let or do I missunderstand it?, Drew Adams, 2024/11/09
- Re: Is this a bug in while-let or do I missunderstand it?, John ff, 2024/11/14
- Sv: Is this a bug in while-let or do I missunderstand it?, arthur miller, 2024/11/10
- Re: Is this a bug in while-let or do I missunderstand it?, Eli Zaretskii, 2024/11/10
- Re: Is this a bug in while-let or do I missunderstand it?, Joost Kremers, 2024/11/10
- Re: Is this a bug in while-let or do I missunderstand it?,
Alfred M. Szmidt <=
- Sv: Is this a bug in while-let or do I missunderstand it?, arthur miller, 2024/11/10
- Sv: Is this a bug in while-let or do I missunderstand it?, arthur miller, 2024/11/10
- Re: Is this a bug in while-let or do I missunderstand it?, Yuri Khan, 2024/11/11
- Sv: Is this a bug in while-let or do I missunderstand it?, arthur miller, 2024/11/11
- Re: Sv: Is this a bug in while-let or do I missunderstand it?, tomas, 2024/11/11
- Re: Is this a bug in while-let or do I missunderstand it?, Joost Kremers, 2024/11/11
- Re: Is this a bug in while-let or do I missunderstand it?, Eli Zaretskii, 2024/11/12
- Re: Is this a bug in while-let or do I missunderstand it?, Joost Kremers, 2024/11/12
- Re: Is this a bug in while-let or do I missunderstand it?, Eli Zaretskii, 2024/11/12
- Re: Is this a bug in while-let or do I missunderstand it?, Joost Kremers, 2024/11/12