emacs-devel
[Top][All Lists]
Advanced

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

Re: cond*


From: Ihor Radchenko
Subject: Re: cond*
Date: Mon, 08 Jan 2024 15:13:10 +0000

Richard Stallman <rms@gnu.org> writes:

>   > >From my reading of your latest spec of the cond*, I feel that it is
>   > getting closer and closer to the features provided by `pcase'. The
>   > description is also getting closer to pcase manual page length.
>
> After eliminating the nested constrained variables, it is only 213 lines.
>
> Are there any pcase features that cond* does not provide an equivalent
> for?

Other than rx, one missing feature is an ability to match against
multiple values in a single condition:

(defun yant/list-sum (list)
  (apply #'+ list))
(pcase '(1 2 3)
  ((and `(,x ,y ,z) (app yant/list-sum (and sum (guard (< 2 sum)))))
   (format "%d + %d + %d = %d; 2 is < %d" x y z sum sum)))
; => "1 + 2 + 3 = 6; 2 is < 6"   

In the above, we first match `(,x ,y ,z) against '(1 2 3) and then
match (and sum (guard (< 2 sum))) against the result of (yant/list-sum '(1 2 3))

Also, `pcase' performs some compiler-like optimizations on the provided
patterns.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>



reply via email to

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