emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: combining cond and let, to replace pcase.


From: Daniel Semyonov
Subject: Re: combining cond and let, to replace pcase.
Date: Fri, 24 Nov 2023 05:08:55 +0200
User-agent: K-9 Mail for Android

>>>>> Richard Stallman writes:

> I've done more work on designing `cond*'; here is what I have now.
> Please send me constructive suggestions, including for features you
> suggest adding.

I think either the name should be changed or the behavior of t as a
condition should be the same as in 'cond', as IMO it could lead to
confusion. Maybe ':always' or ':continue' could be used instead?

Other than that this seems very simple and easy to understand, I would
honestly much prefer this over 'pcase'.

> Here are three macros that would be useful as conditions in `cond*'
> but can also be used elsewhere.

These also seem nice, but they make the ':match' condition
almost pointless? AFAIU, the following should be equivalent:

(cond* (:bind foo bar (x foobar))
;; IMO changing t to ':always' would make it very clear what's
;; going on here.
(t (match-set `(a ,foo ,bar) x))
((match-set `(b ,foo ,bar) x)
;; do stuff and exit
)
;; more conditions...
)

(cond* (:bind (x foobar))
(:match (`(a ,foo ,bar) x))
(:match (`(b ,foo ,bar) x)
;; do stuff and exit...
)
;; more conditions...
)

The only usecase for ':match' (which can't really be fulfilled by the
macros) is binding "new" variables (which haven't been bound using
':bind' beforehand), but I think requiring an explicit ':bind' is more
clear, and would make it easier to quickly identify local variable
names. It could also be better for people new to ELisp eventually, since
these macros would be more likely familiar to them already (due to their
potential usage outside of 'cond*') when compared to ':match'.

And a minor nitpick, I think it would be better to rename 'match-bind'
to 'match-let', to mirror other macros like 'if-let' (maybe even change
':bind' to ':let').

Regards,
Daniel

reply via email to

[Prev in Thread] Current Thread [Next in Thread]