unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* pcase defuns
@ 2021-12-19  4:53 Andrew Hyatt
  2021-12-19  8:34 ` Tassilo Horn
                   ` (4 more replies)
  0 siblings, 5 replies; 25+ messages in thread
From: Andrew Hyatt @ 2021-12-19  4:53 UTC (permalink / raw)
  To: emacs-devel


Hi all,

As a part of a personal project, I wrote a way to define functions 
in an equivalent way to pcases.  For example:

(pcase-defun mytest (a b _)
  "Match on 'a 'b with the third argument a wildcard"
  "a b match")

(pcase-defun mytest (c ,var _)
  "Match on 'c binding VAR, with the third argument a wildcard"
  (format "c %s match" var) )

(mytest 'a 'b 'c) -> "a b match"
(mytest 'c 100 'c) -> "c 100 match"

This is all accomplished by a few small but tricky macros and a 
hashtable that holds all the rules.

I find this method of programming quite useful for certain kinds 
of problems, and pcase is close to what I want, but using pcase 
forced me to encapsulate all of my pattern matching logic in one 
function. Being able to have it spread out in pattern matching 
functions seems much nicer to me.

If this is of interest, I can either add this to the pcase module 
itself, create a package in gnu elpa, or (if there's some reason 
that it shouldn't be done) just keep it in a personal repository.

I'll wait for some guidance before creating a final version, with 
tests, wherever it should go.



^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2022-04-19  3:48 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-19  4:53 pcase defuns Andrew Hyatt
2021-12-19  8:34 ` Tassilo Horn
2021-12-19 15:33   ` Andrew Hyatt
2021-12-19 17:16     ` Tassilo Horn
2021-12-19 19:05       ` Stefan Monnier
2021-12-20  5:56         ` Tassilo Horn
2021-12-22 14:07   ` LdBeth
2021-12-19 17:23 ` Stefan Monnier
2021-12-19 21:08   ` Andrew Hyatt
2021-12-21  4:15     ` Richard Stallman
2021-12-21  5:20       ` Andrew Hyatt
2021-12-22  4:18         ` Richard Stallman
2021-12-23  1:52           ` Andrew Hyatt
2021-12-24  4:13             ` Richard Stallman
2021-12-21 15:32     ` Stefan Monnier
2021-12-20  4:43 ` Richard Stallman
2021-12-23  2:30 ` Po Lu
2022-03-26 17:41 ` Andrew Hyatt
2022-03-27  9:31   ` Stefan Monnier
2022-03-27 18:17     ` Andrew Hyatt
2022-03-28  4:15   ` Richard Stallman
2022-03-30  1:28     ` Andrew Hyatt
2022-03-31  4:27       ` Richard Stallman
2022-04-17 22:09         ` Andrew Hyatt
2022-04-19  3:48           ` Richard Stallman

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).