From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Michael Heerdegen Newsgroups: gmane.emacs.devel 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 Message-ID: <87a7mxirwd.fsf@web.de> References: <20151216202605.GA3752@acm.fritz.box> <56893C8C.3060200@yandex.ru> <87oad2irtd.fsf@fencepost.gnu.org> <5689456A.1010601@yandex.ru> <87egdy8tyz.fsf@fencepost.gnu.org> <56895FDE.4060406@yandex.ru> <8760za8r4a.fsf@fencepost.gnu.org> <87h9iunkcg.fsf@web.de> <87h8hc4xw2.fsf_-_@web.de> <83tvlcsnee.fsf@gnu.org> <87pnw037ar.fsf@web.de> <83ftwvs7y9.fsf@gnu.org> <877ei7mkfh.fsf@web.de> <87a7mze7tl.fsf@web.de> <87zhuykjjh.fsf@web.de> <871s8aesdc.fsf@portable.galex-713.eu> <87tvl6dc3e.fsf_-_@portable.galex-713.eu> <87d0rud6gt.fsf_-_@portable.galex-713.eu> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1540768544 25274 195.159.176.226 (28 Oct 2018 23:15:44 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 28 Oct 2018 23:15:44 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: Eli Zaretskii , emacs-devel@gnu.org, Stefan Monnier , Dmitry Gutov To: "Garreau\, Alexandre" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Oct 29 00:15:40 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gGuHU-0006Ts-3Z for ged-emacs-devel@m.gmane.org; Mon, 29 Oct 2018 00:15:40 +0100 Original-Received: from localhost ([::1]:42552 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gGuJa-0006Wo-A0 for ged-emacs-devel@m.gmane.org; Sun, 28 Oct 2018 19:17:50 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52628) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gGuIg-0006WV-Q2 for emacs-devel@gnu.org; Sun, 28 Oct 2018 19:16:59 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gGuIZ-0002dM-Tu for emacs-devel@gnu.org; Sun, 28 Oct 2018 19:16:50 -0400 Original-Received: from mout.web.de ([212.227.15.14]:36221) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gGuIS-0002Vl-KZ; Sun, 28 Oct 2018 19:16:41 -0400 Original-Received: from drachen.dragon ([94.218.210.177]) by smtp.web.de (mrweb002 [213.165.67.108]) with ESMTPSA (Nemesis) id 0McFcd-1fxrhi2wtT-00JY78; Mon, 29 Oct 2018 00:16:21 +0100 Original-Received: from drachen.dragon ([94.218.210.177]) by smtp.web.de (mrweb002 [213.165.67.108]) with ESMTPSA (Nemesis) id 0McFcd-1fxrhi2wtT-00JY78; Mon, 29 Oct 2018 00:16:21 +0100 In-Reply-To: <87d0rud6gt.fsf_-_@portable.galex-713.eu> (Alexandre Garreau's message of "Sun, 28 Oct 2018 05:45:54 +0100") X-Provags-ID: V03:K1:1drPHUVmSr6gC6sK+p3OjYIGQypT5cdptJE6hQHDUVq0g8cMVbx AemjPZtJbQU21jQRmCzI3UuCqCesMnXTgNINxK9LRts5LCQ6rQTFEUhKIrpolaB5VWCOosk GJcqXV5I5k5leZlPPL41QmHY/obYM6OK7Kf975nIQ688dOOTJvH4LstnPqycJaYgbZWn0Fa bwBJRV3ZCNdhl9Ita3nWA== X-UI-Out-Filterresults: notjunk:1;V01:K0:/2MxATWeyLQ=:80prgPicsQY6pqmOgQs3yc VOyMRQllkfoL/yJR1XWsy8cdldklDKo7xPRoYNL77tSrXBSWRlce6UzD9NlSTGEucwbj7SWIa ygKV79pFuQVvldzadXlBITr+aY6qOD+HTs413XvBaMPkHDIEPCL9HvgO/zahxLQZkrGqGYCIa nUVWvc+yQTf3/6QV4g1+iGNqiXVVtH5Ohv9uJVo+0MwovRg0+hzGmfk62vd4TmvdjO2W9an7A eeCN/1n0TDkb57S515sJ83VsSqIRkgfzk7H2HytcyA6rKmyhPO0dliiA/xkJ5mZERWDhi21/C 2S0DNhgdWNX9+DSjoXcAUVAkRYdLACKkRFHONEuktVGDH+7dLGsIavK/UMgGzYn0UO7Mh6u13 Dx9g/G9q5tdnlh3lUgAsi1/Nszu4Vx97kPxzNA1wXPPQFdOPNmQE9cx+n+2NaMdZEeMByPBRl BrC9q6Q+Q6j6dpubbgtFHAPMLcfLu+Y3UQ+AEHigE2tytz5SpvXM1hWMx6e45K4xMAysm9uXY WgXjWCiLOr/bzTc+JHzhUJDlSlhFP0ZzN/zWDaZm2Akly0OxmvvLd1A9zkbhDlx1xmYO2R8XQ lq3L4dsoqvqXWGZOBjbwgbc4LofwKdrk6EjZLoi+k/LUtrc9IcRFBRdtpf5zlbFScmNVuphT2 S7JoCcfPIvui9GSvWBsCODa8H82VQ/q0tovakhJguX2tag2De6AVCuG3xiw+Io5Q5OX4KkXK+ 9Xi/K9llu6+NOA14zhQU7xHv2c2HT7npVlEl2bDUIQCo/ObIkvpMY+no5wxpivibGvrWpU2s X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.15.14 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:230760 Archived-At: "Garreau, Alexandre" 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 =E2=80=9C(match '((1 . 2)) ((assoc 1 x) = x))=E2=80=9D > returns 2), to match content of an alist, or =E2=80=9Cproperty=E2=80=9D f= or 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.