emacs-devel
[Top][All Lists]
Advanced

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

Re: How other pattern-matching lisps do [Was: Re: pcase ` meaning [Was:


From: Michael Heerdegen
Subject: Re: How other pattern-matching lisps do [Was: Re: pcase ` meaning [Was: Re: Replace trivial pcase occurrences in the Emacs sources]]
Date: Mon, 29 Oct 2018 00:16:18 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

"Garreau, Alexandre" <address@hidden> writes:

> As you can see, it also supports `not', and some facilities for OOP.

BTW, el-search supports `not'.  AFAIK it would be trivial to add `not'
to pcase, but Stefan wants to wait for an idea of how to do so
efficiently.

> or `(assoc 1 alist-pattern)' (so “(match '((1 . 2)) ((assoc 1 x) x))”
> returns 2), to match content of an alist, or “property” for plists.

Oh, there are some emacs libraries you need to load to get corresponding
pcase macros.  For example these:

-- (eieio &rest FIELDS)

Pcase patterns that match EIEIO object EXPVAL.

-- (seq &rest PATTERNS)

Build a `pcase' pattern that matches elements of SEQUENCE.

-- (rx &rest REGEXPS)

Build a `pcase' pattern matching `rx' REGEXPS in sexp form.

-- (cl-struct TYPE &rest FIELDS)

Pcase patterns that match cl-struct EXPVAL of type TYPE.

-- (radix-tree-leaf VPAT)

Build a `pcase' pattern that matches radix-tree leaf EXPVAL.
VPAT is a `pcase' pattern to extract the value.

-- (map &rest ARGS)

Build a `pcase' pattern matching map elements.


The last one supports matching alists conveniently.

> However something such as (pcase-defmacro list (&rest args) ``(,@args))

The normal backquote macro recursively handles also the backquotes and
unquotes that are meant for pcase, so you must avoid unwanted
processing.  I would write it as

#+begin_src emacs-lisp
(pcase-defmacro list (&rest args)
  `(,'\` ,(mapcar (lambda (thing) `(,'\, ,thing)) args)))
#+end_src

BTW, if you load "el-search-x.el", there is an `l' pattern defined, also
for matching lists, which also avoids ``' but has a completely different
semantics: it's more inspired by grep patterns, with the goal of
allowing to use very short input to find function definitions and such.


Michael.



reply via email to

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