unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Allow underscore in non-binding clauses of `if-let*` and friends
@ 2024-11-12 13:36 Joost Kremers
  2024-11-12 17:55 ` Alfred M. Szmidt
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Joost Kremers @ 2024-11-12 13:36 UTC (permalink / raw)
  To: emacs-devel@gnu.org

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



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Allow underscore in non-binding clauses of `if-let*` and friends
  2024-11-12 13:36 Allow underscore in non-binding clauses of `if-let*` and friends Joost Kremers
@ 2024-11-12 17:55 ` Alfred M. Szmidt
  2024-11-13 11:03   ` Joost Kremers
  2024-11-12 20:13 ` Jens Schmidt
  2024-11-13 10:22 ` Sean Whitton
  2 siblings, 1 reply; 6+ messages in thread
From: Alfred M. Szmidt @ 2024-11-12 17:55 UTC (permalink / raw)
  To: Joost Kremers; +Cc: emacs-devel

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

Isn't this already allowed?  LET* allows for it, or is this another of
those this is not really LET* but something else situation?



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Allow underscore in non-binding clauses of `if-let*` and friends
  2024-11-12 13:36 Allow underscore in non-binding clauses of `if-let*` and friends Joost Kremers
  2024-11-12 17:55 ` Alfred M. Szmidt
@ 2024-11-12 20:13 ` Jens Schmidt
  2024-11-12 20:23   ` Joost Kremers
  2024-11-13 10:22 ` Sean Whitton
  2 siblings, 1 reply; 6+ messages in thread
From: Jens Schmidt @ 2024-11-12 20:13 UTC (permalink / raw)
  To: Joost Kremers, emacs-devel@gnu.org

On 2024-11-12  14:36, Joost Kremers wrote:

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

Actually, in a recent master your snippet even expands to

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

with (uninterned) symbols s being used in place of `_'.

Seems that Michael has already seen to that:

  commit e680827e814e155cf79175d87ff7c6ee3a08b69a
  Author: Michael Heerdegen <michael_heerdegen@web.de>
  Date:   Fri Feb 16 22:07:18 2024 +0100

    Don't warn about _ not left unused in if-let and alike
    
    The macro expansions did not leave a variable _ unused; this triggered
    an irritating compiler warning (bug#69108).
    
    * lisp/subr.el (internal--build-binding): Handle bindings of the form
    (_ EXPR) separately.

And I might consider using underscores instead of alignment ...




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Allow underscore in non-binding clauses of `if-let*` and friends
  2024-11-12 20:13 ` Jens Schmidt
@ 2024-11-12 20:23   ` Joost Kremers
  0 siblings, 0 replies; 6+ messages in thread
From: Joost Kremers @ 2024-11-12 20:23 UTC (permalink / raw)
  To: Jens Schmidt; +Cc: emacs-devel@gnu.org

On Tue, Nov 12 2024, Jens Schmidt wrote:
> On 2024-11-12  14:36, Joost Kremers wrote:
>
>> 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.
[...]
> Seems that Michael has already seen to that:

Oh, great! :-)

> And I might consider using underscores instead of alignment ...

With this commit on the books, I'll do that, too. I'll live with the
warnings for the time being.

-- 
Joost Kremers
Life has its moments



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Allow underscore in non-binding clauses of `if-let*` and friends
  2024-11-12 13:36 Allow underscore in non-binding clauses of `if-let*` and friends Joost Kremers
  2024-11-12 17:55 ` Alfred M. Szmidt
  2024-11-12 20:13 ` Jens Schmidt
@ 2024-11-13 10:22 ` Sean Whitton
  2 siblings, 0 replies; 6+ messages in thread
From: Sean Whitton @ 2024-11-13 10:22 UTC (permalink / raw)
  To: Joost Kremers; +Cc: emacs-devel@gnu.org

Hello,

On Tue 12 Nov 2024 at 02:36pm +01, Joost Kremers wrote:

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

As has been pointed out it's already implicitly allowed because let*
allows it.  Given this, I suggest not changing the macro docstrings.

On the other hand, I think it would be good to add an explanation and/or
example in the manual.  Perhaps propose another patch once we've got
your other one applied, though.

-- 
Sean Whitton



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Allow underscore in non-binding clauses of `if-let*` and friends
  2024-11-12 17:55 ` Alfred M. Szmidt
@ 2024-11-13 11:03   ` Joost Kremers
  0 siblings, 0 replies; 6+ messages in thread
From: Joost Kremers @ 2024-11-13 11:03 UTC (permalink / raw)
  To: Alfred M. Szmidt; +Cc: emacs-devel

On Tue, Nov 12 2024, Alfred M. Szmidt wrote:
>    ```
>    (if-let* ((_ (foo (some-computation)))
> 	     (_ (bar (some-other-computation)))
> 	     (baz (y-or-n-p "Hi? ")))
>        (message "yes"))
>    ```
>
> Isn't this already allowed?  LET* allows for it, or is this another of
> those this is not really LET* but something else situation?

Yes, it's allowed, it's just that in Emacs 29 (which I'm using), it's
flagged by flycheck. That has been fixed in Emacs 30, though.

-- 
Joost Kremers
Life has its moments



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-11-13 11:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-12 13:36 Allow underscore in non-binding clauses of `if-let*` and friends Joost Kremers
2024-11-12 17:55 ` 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

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