all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Joost Kremers <joostkremers@fastmail.fm>
To: "emacs-devel@gnu.org" <emacs-devel@gnu.org>
Subject: Allow underscore in non-binding clauses of `if-let*` and friends
Date: Tue, 12 Nov 2024 14:36:29 +0100	[thread overview]
Message-ID: <868qto4lr6.fsf@fastmail.fm> (raw)

Hi all,

My apologies for launching yet another thread on `if-let*` c.s., but this
should be a small one and I didn't want it to get buried in one of the
other threads...

`if-let*` c.s. allow non-binding clauses in their VARLIST/SPEC argument.
It was suggested in one of the other threads that aligning those with the
VALUE-FORM of the binding clauses would help to distinguish them:

```
(if-let* ((    (foo (some-computation)))
          (    (bar (some-other-computation)))
          (baz (y-or-n-p "Hi? ")))
    (message "yes"))
```

I'm sure I'm not the only one who finds this a bit jarring, though I agree
that the "normal" formatting is difficult to read:

```
(if-let* (((foo (some-computation)))
          ((bar (some-other-computation)))
          (baz (y-or-n-p "Hi? ")))
    (message "yes"))
```

The reason being that you really need to count parentheses to see that
`(foo (some-computation))` is *not* a binding form where `foo` is bound to
the result of `(some computation)`. I don't like counting parentheses.

Instead, one could use underscores:

```
(if-let* ((_ (foo (some-computation)))
          (_ (bar (some-other-computation)))
          (baz (y-or-n-p "Hi? ")))
    (message "yes"))
```

We already use underscore to mean "ignore this variable" in several
contexts, so this seems consistent. It also macro-expands to the same
code as the one without underscore, so it's not less efficient.

The only problem AFAICT is that flycheck complains: "variable `_' not left
unused". This, I assume, is due to the fact that in the expansion of this
`if-let*`, `_' is indeed used:

```
(let*
    ((_
      (and t
           (foo
            (some-computation))))
     (_
      (and _      ; <=== *used here*
           (bar
            (some-other-computation))))
     (baz
      (and _      ; <=== *and here*
           (y-or-n-p "Hi? "))))
  (if baz
      (message "yes")))
```

WDYT? Would it be a good idea to officially support this and mention it in
the manual? (Not necessarily recommending it, but at least mention it as an
alternative option.)

If yes, what would it take to shut up flymake in this case? (I have no idea
how flymake works, so it'd be helpful if someone pointed me in the right
direction.)

TIA


-- 
Joost Kremers
Life has its moments



             reply	other threads:[~2024-11-12 13:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-12 13:36 Joost Kremers [this message]
2024-11-12 17:55 ` Allow underscore in non-binding clauses of `if-let*` and friends Alfred M. Szmidt
2024-11-13 11:03   ` Joost Kremers
2024-11-12 20:13 ` Jens Schmidt
2024-11-12 20:23   ` Joost Kremers
2024-11-13 10:22 ` Sean Whitton

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

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

  git send-email \
    --in-reply-to=868qto4lr6.fsf@fastmail.fm \
    --to=joostkremers@fastmail.fm \
    --cc=emacs-devel@gnu.org \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.