|
From: | arthur miller |
Subject: | Sv: [External] : Re: Is this a bug in while-let or do I missunderstand it? |
Date: | Sat, 9 Nov 2024 19:32:57 +0000 |
>IMHO, this is a problem with all of the
>if/and/when/while-let[*] thingies.
Only while-let.
>uses them a lot then she probably knows what
>goes on, in what sequence. But a priori it's
>not so clear.
>
>This may just mean that the doc needs to take
>pains to be very clear, maybe even with examples
>or by showing a macro expansion explicitly.
>
>Using catch/throw, let[*], and/if/when/while
>together is always _clearer_, IMO. And it's
>often no more verbose. Witness all of the
I don't think so. As much as I have understood
if-let, when-let and unique for elisp while-let,
are an "informal formalization", or just a shorthand
for following idiom:
(let ((some-var init-form))
(if some-var than-form else-form))
Similar for when-let. Consider also a bigger piece
of code, where you have longer let-form, and want
to do some loop:
(let ((var1 init1)
...
(varN initN)
(loop-invarant init-loop-invariang))
....
(while loop-invariant
...)
...)
In this context you are leaking loop-invariant in the
entire scope of enclosing let-form, whereas
(let ((var1 init1)
...
(varN initN))
....
(while ((loop-invariant init-loop-invariant))
...)
...)
limits 'loop-invariant' to the lexical environment
of while loop. You can compare this to pre- C++11
standards where compilers would leak loop invariants
after the scope of the loop:
for (int i=0; i<10; i++) {
...
}
i = 2; <-- i visible outside of the for-loop scope
Limiting scope of variables to the lexical scope
where they matter helps to minimize accidental
usages, and also make code easier to read and understand.
Från: Drew Adams <drew.adams@oracle.com>
Skickat: den 9 november 2024 19:07 Till: Eli Zaretskii <eliz@gnu.org>; Alfred M. Szmidt <ams@gnu.org> Kopia: yuri.v.khan@gmail.com <yuri.v.khan@gmail.com>; arthur.miller@live.com <arthur.miller@live.com>; emacs-devel@gnu.org <emacs-devel@gnu.org> Ämne: RE: [External] : Re: Is this a bug in while-let or do I missunderstand it? IMHO, this is a problem with all of the
if/and/when/while-let[*] thingies. If someone uses them a lot then she probably knows what goes on, in what sequence. But a priori it's not so clear. This may just mean that the doc needs to take pains to be very clear, maybe even with examples or by showing a macro expansion explicitly. Using catch/throw, let[*], and/if/when/while together is always _clearer_, IMO. And it's often no more verbose. Witness all of the discussion about <X>-let* versus <X>-let names and this current discussion. The name itself doesn't clearly tell you what it does... which is OK, but only if the doc tells you that clearly. I'm not saying no one should use, or Elisp shouldn't provide, if/and/when/while-let[*] thingies. I'm just saying (1) I don't find them helpful, personally (I don't use them), and (more importantly) (2) if we provide them then their doc needs to be very specific about what _exactly_ they do, and when (if not also how). |
[Prev in Thread] | Current Thread | [Next in Thread] |