emacs-devel
[Top][All Lists]
Advanced

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

combining cond and let, to replace pcase.


From: Richard Stallman
Subject: combining cond and let, to replace pcase.
Date: Fri, 17 Nov 2023 22:03:56 -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. ]]]

  > I've thought before that it would be nice to have a cond-let construct,
  > like if-let and when-let.

Here's an example to show what I have come up with along these lines:

(cond* (:bind (x foobar) y z (foo 5) a)  ;; variables to bind, as in let
       ;; I'm also thinking of using nil instead of :bind.

       ;; t as condition means run this clause unconditionally
       ;; then continue with next clause.
       (t do-this-unconditionally-and-dont-stop...)

       ;; Tests with a new function `match' which I'm going to work on next.
       ((match x 'foo) ...)

       ;; t in the last clause means the same as in previous clauses,
       ;; but you can think of it as being the same as in `cond'.
       (t do-this-as-last-resort)
       )

Rhe idea is that conf* does part of pcase's added functionality, and
`match' will do the rest.  But it is not necessary to cram _all_ the
additional matching functionality (to compare to pcase) into a single
new function.  We could have more than one new function, eacn for its
own kind of pattern matching.

Some of them could do destructuring as well as matching.

I hoipe that using a few constructs to divide up the job will avoid
the kludginess of pcase's bells-and-whistles-for-everything approach,
resulting in something equally convenient but made of simple components.

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