Subject: Re: bug#73853: Should and-let* become a synonym for when-let*?

From: Michael Heerdegen <[email-masked]>
Date: Thu, 23 Jan 2025 03:00:58 +0100

Stefan Monnier <[email-masked]> writes:

> > I would always ask: which of the semantics did we choose again...?
>
> That's easy to fix: disallow or strongly discourage empty bodies.
> We already do that in various places and it would be very natural to do
> that in `when-let*` as well.
> Currently in Emacs itself, `grep` finds 681 uses of `when-let(*)` and
> only one of them has an empty body (and I'd argue it's an error: the
> last "binding" is `((push finext extlist-new))` which macro expands to
> something silly; not sure if the bytecompiler manages to unsillify the
> code).
> The score is a bit less one-sided for `and-let*` where I count 25 empty
> bodies among 140 uses (the vast majority of them in ERC and Tramp).

This is my personal perspective but: `and-let*' doesn't have a body!
It's final condition naturally doesn't need to be bound and thus can be
put at the final position after the bindings.

> Also, it's easier to remember the answer if you have to remember it only
> for `when-let*` rather than having to remember it for both `and-let*` and
> `when-let*`.

I never had a problem to remember any of the semantics of those macros.
They are natural.

> Incidentally, `and-let*` is member of a rather small club of forms where
> en empty body is not treated as a body that returns nil.  I was able
> to remember only 3 other forms that have this property (one of which is
> never used, AFAICT).  I don't think forms should wear this property as
> a badge of honor.

Yes, because it should not be seen as body, in my opinion.  I would
remove the &rest and make it an optional final statement.

> In the case of `and-let*`, it seems the tradeoff is not code size nor
> verbosity, but only a reluctance by some developers to rely on
> `when(-let)`s return value, even tho it's documented/reliable.

Please not without context: it's so because of the name and the
semantics a `when' statement usually suggests.  If this was Prolog I
would see it differently.

> So maybe instead of converting `and-let*` to `when-let*` we should
> recommend converting them to `if-let*`, where I don't think anyone has
> ever expressed an expectation that `if(-let)` doesn't return a value or
> that it's unclear what value it would return if the (else) body is
> empty.

Well, I did think about it.  If `if' or `if-let*' is used as a condition
I would always specify THEN and (one) ELSE.  But yes, definitely better
than `when-let'.

> > So isn't your personal taste in this case here relevant too, for what
> > you want to do?
>
> Definitely.  I did not intend to imply otherwise.

Ok.  But why do you think that your taste is the better one, then?  Or
shared by more people?

Michael.