emacs-devel
[Top][All Lists]
Advanced

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

Re: cond*


From: Richard Stallman
Subject: Re: cond*
Date: Fri, 26 Jan 2024 22:37:45 -0500

[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

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

Understanding this was a struggle, but I think it can be done with

  (cond* ((match* `(,x ,y ,z) list-of-three))
         ((< 2 (+ x y z))
          success)))

It is not the one condition which is the goal you specified, but given
the flexibility of cond* it doesn't need to be one condition.  And it
is much clearer than the pcase code to do the same job.


-- 
Dr Richard Stallman (https://stallman.org)
Chief GNUisance of the GNU Project (https://gnu.org)
Founder, Free Software Foundation (https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)





reply via email to

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