unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: arthur miller <arthur.miller@live.com>,
	Eli Zaretskii <eliz@gnu.org>, "Alfred M. Szmidt" <ams@gnu.org>
Cc: "yuri.v.khan@gmail.com" <yuri.v.khan@gmail.com>,
	"emacs-devel@gnu.org" <emacs-devel@gnu.org>
Subject: RE: [External] : Re: Is this a bug in while-let or do I missunderstand it?
Date: Sat, 9 Nov 2024 22:36:34 +0000	[thread overview]
Message-ID: <DS7PR10MB523275234C42F8AFD6274D45F35E2@DS7PR10MB5232.namprd10.prod.outlook.com> (raw)
In-Reply-To: <DU2PR02MB1010973AF0F33B33BB48C6F36965E2@DU2PR02MB10109.eurprd02.prod.outlook.com>

[-- Attachment #1: Type: text/plain, Size: 4680 bytes --]

Below.

From: arthur miller Sent: Saturday, November 9, 2024 11:33 AM
>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.

Only while-let.

The lack of obvious behavior/meaning and clear doc is a problem with them in general, IMO.

In particular, it wouldn't hurt to show an example of what each can expand to, in terms of let[*] etc. We do that in the Elisp manual when introducing cond, for example:

For example: (if A B C)  ≡ (cond (A B) (t C))

(We could even usefully do it to show let* in terms of let.)

>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.

I don't think so.

(catch/throw aren't needed for some of the *-let constructs, of course.)

IMO, use of explicit let, for binding, and explicit if/when/etc. for control flow, is clear. And if you don't use the *-let thingies much, or are new to them, then the former are clearer. Hence the need for good doc for the *-let combination bind&control constructs, at a minimum.

As you say, the *-let constructs are just "shorthand". And not much shorter, typically. Shorthand, but mentally more complex. The complexity isn't visual, it's in their meanings/behaviors, i.e., mental.

I'm not against all combinations of binding constructs with control constructs. E.g., constructs such as dolist bind vars. I just don't see much mileage/clarity gain from the *-let thingies. YMMV. At a minimum, their doc should be made very clear.

(let ((var1 init1) ... (varN initN)
      (loop-invarant init-loop-invariant))
  ...
  (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.

What's your argument? That there's no need to bind a local var for init-loop-invariant? OK. How's that relevant here?

(And there's no *-let construct in either of those examples, so ... what are you really comparing/demonstrating?)

In any case, if you did need a local var and wanted to keep its scope within the while you'd just wrap the while with its own let - end of story:

(let ((var1 init1) ... (varN initN)
  ...
  (let ((loop-invarant init-loop-invariant)) (while loop-invariant ...))
 ...)

Using a separate let makes clear where you want/need a separate binding scope.
___

It's enough for someone to scan this mail thread, to see possible confusion over what while-let does and how/when/where it does what --> QED.

E.g., suggestions such as this, to help clarify the meaning/behavior of a while-let, make clear that it isn't so clear on its own:


>I'd align such clauses like this:

>

> (while-let ((  b)

>             (  (< b end))

>             (e (next-single-property-change

>                  (1+ b) 'erc--msg nil end)))

>   ...)

>

>to emphasize that.

I'm not saying such intentional formatting wouldn't help; it could. But suggesting such formatting just underlines how unclear the while-let construct seems to be, a priori.

Again, maybe a doc improvement could help. Or a pointer to this thread, where the back-&-forth might unconfuse someone a bit... ;-)

Från: Drew Adams Skickat: den 9 november 2024 19:07

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).

[-- Attachment #2: Type: text/html, Size: 19775 bytes --]

  reply	other threads:[~2024-11-09 22:36 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-08 16:25 Is this a bug in while-let or do I missunderstand it? arthur miller
2024-11-08 19:23 ` Philip Kaludercic
2024-11-09  3:30   ` Sv: " arthur miller
2024-11-09  9:29 ` Yuri Khan
2024-11-09 13:03   ` Sv: " arthur miller
2024-11-09 13:15     ` Yuri Khan
2024-11-09 13:38       ` Sv: " arthur miller
2024-11-09 13:41         ` Yuri Khan
2024-11-09 13:47           ` Sv: " arthur miller
2024-11-09 14:04             ` Yuri Khan
2024-11-09 14:44               ` Sv: " arthur miller
2024-11-09 16:33               ` Alfred M. Szmidt
2024-11-09 16:44                 ` Eli Zaretskii
2024-11-09 16:53                   ` Eli Zaretskii
2024-11-09 17:33                   ` Andreas Schwab
2024-11-09 18:07                   ` [External] : " Drew Adams
2024-11-09 18:18                     ` Alfred M. Szmidt
2024-11-09 20:02                       ` Jens Schmidt
2024-11-09 20:38                         ` Alfred M. Szmidt
2024-11-09 21:18                           ` Joost Kremers
2024-11-10 11:44                         ` Alfred M. Szmidt
2024-11-10 12:24                           ` Better documentation for non-binding clauses of if-let and friends Jens Schmidt
2024-11-10 14:51                             ` Sean Whitton
2024-11-10 16:58                               ` Jens Schmidt
2024-11-11 10:03                               ` Alfred M. Szmidt
2024-11-11  8:20                             ` Alfred M. Szmidt
2024-11-09 19:32                     ` Sv: [External] : Re: Is this a bug in while-let or do I missunderstand it? arthur miller
2024-11-09 22:36                       ` Drew Adams [this message]
2024-11-09 22:53                         ` Drew Adams
2024-11-14 21:50                   ` John ff
2024-11-09 20:29                 ` Sv: " arthur miller
2024-11-10  6:22                   ` Eli Zaretskii
2024-11-10 10:40                     ` Joost Kremers
2024-11-10 12:10                       ` Alfred M. Szmidt
2024-11-10 19:49                         ` Sv: " arthur miller
2024-11-10 18:18                     ` arthur miller
2024-11-11  5:13                       ` Yuri Khan
2024-11-11  8:49                         ` Sv: " arthur miller
2024-11-11 12:23                           ` tomas
2024-11-11 22:41                     ` Joost Kremers
2024-11-12 12:19                       ` Eli Zaretskii
2024-11-12 12:45                         ` Joost Kremers
2024-11-12 14:34                           ` Eli Zaretskii
2024-11-12 15:32                             ` Joost Kremers
2024-11-12 23:45                         ` Joost Kremers
2024-11-13  9:45                           ` Sean Whitton
2024-11-13  9:56                             ` Sean Whitton
2024-11-13 11:00                               ` Joost Kremers
2024-11-13 12:17                                 ` Sean Whitton
2024-11-14  7:55                                 ` Eli Zaretskii
2024-11-14  8:21                                   ` Joost Kremers
2024-11-14 21:51                               ` John ff
2024-11-14 21:52                                 ` John ff
2024-11-09 21:47             ` Sv: " Joost Kremers
2024-11-09 22:07               ` Sv: " arthur miller
2024-11-10  6:07               ` Andreas Schwab

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DS7PR10MB523275234C42F8AFD6274D45F35E2@DS7PR10MB5232.namprd10.prod.outlook.com \
    --to=drew.adams@oracle.com \
    --cc=ams@gnu.org \
    --cc=arthur.miller@live.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=yuri.v.khan@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).