From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: "Garreau\, Alexandre" Newsgroups: gmane.emacs.devel Subject: Re: pcase ` meaning Date: Tue, 30 Oct 2018 01:27:42 +0100 Message-ID: <87efc8qnwh.fsf@portable.galex-713.eu> References: <20151216202605.GA3752@acm.fritz.box> <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> <87efc9isxj.fsf@web.de> <87tvl5653j.fsf@portable.galex-713.eu> <38aa830d-740e-af4d-9071-9aa0d9c10f04@gmail.com> 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 1540859152 10875 195.159.176.226 (30 Oct 2018 00:25:52 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 30 Oct 2018 00:25:52 +0000 (UTC) User-Agent: Gnus (5.13), GNU Emacs 25.1.1 (i686-pc-linux-gnu, GTK+ Version 3.22.11) of 2017-09-15, modified by Debian Cc: emacs-devel@gnu.org To: =?utf-8?Q?Cl=C3=A9ment?= Pit-Claudel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Oct 30 01:25:47 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 1gHHqr-0002h1-8I for ged-emacs-devel@m.gmane.org; Tue, 30 Oct 2018 01:25:45 +0100 Original-Received: from localhost ([::1]:49831 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHHsx-0001Vq-Bk for ged-emacs-devel@m.gmane.org; Mon, 29 Oct 2018 20:27:55 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33299) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHHsq-0001Vj-Te for emacs-devel@gnu.org; Mon, 29 Oct 2018 20:27:49 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHHsp-000293-Ty for emacs-devel@gnu.org; Mon, 29 Oct 2018 20:27:48 -0400 Original-Received: from portable.galex-713.eu ([2a00:5884:8305::1]:59604) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gHHsp-000282-LK for emacs-devel@gnu.org; Mon, 29 Oct 2018 20:27:47 -0400 Original-Received: from localhost ([::1] helo=portable.galex-713.eu) by portable.galex-713.eu with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gHHsl-0008Pk-6p; Tue, 30 Oct 2018 01:27:44 +0100 PGP-FINGERPRINT: E109 9988 4197 D7CB B0BC 5C23 8DEB 24BA 867D 3F7F Accept-Language: fr, en, eo, it, br In-Reply-To: <38aa830d-740e-af4d-9071-9aa0d9c10f04@gmail.com> (=?utf-8?Q?=22Cl=C3=A9ment?= Pit-Claudel"'s message of "Mon, 29 Oct 2018 13:26:13 -0400") X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:5884:8305::1 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:230788 Archived-At: On 2018-10-29 at 13:26, Cl=C3=A9ment Pit-Claudel wrote: > On 28/10/2018 19.09, Garreau, Alexandre wrote: >> the pattern look like what the data should be. adding =E2=80=9C`=E2=80= =9D and =E2=80=9C,=E2=80=9D >> destroy this feature, because the pattern no longer looks like what >> is matched. > > Maybe it's a matter of perspective? Adding "`" and "," is precisely > what makes the pattern look like the data: the invariant is that if > you have a match, repeating the pattern produces the original data. Oh, you mean =E2=80=9Crepeating *in the body*=E2=80=9D? Didn=E2=80=99t not= ice that. Indeed, this is something I didn=E2=80=99t notice: that=E2=80=99s making me way mor= e comfortable with =E2=80=9C`=E2=80=9D (as it is used this way in all schemes too, so its= meaning couldn=E2=80=99t and won=E2=80=99t be changed). But normally, even if, as a side effect, pattern matching match in appearance what it=E2=80=99d be if you wanted to repeat the pattern, repeat= ed, like here: #+BEGIN_SRC emacs-lisp (pcase `(1 2 3) (`(,a ,b ,c) `(,a ,b ,c))) #+END_SRC (or may appear also as '(1 2 3), or (list 1 2 3)) #+BEGIN_SRC ocaml match [1;2;3] with [a;b;c] -> [a;b;c] #+END_SRC But this is a non-primordial side effect. Notice how in the later case the matched data *always* look the same as the pattern (beside replacing a number per an identifier): *that=E2=80=99s* the purpose of pattern matchi= ng. While in the lisp case you got those extra =E2=80=9C,=E2=80=9D. Of course, these might not cause problem if, incidentally, you were to use them in matched data too (but it=E2=80=99d be odd): #+BEGIN_SRC emacs-lisp (pcase `(,x ,y ,z) (`(,a ,b ,c) `(,a ,b ,c))) #+END_SRC But that will rarely happen, as it is somewhat redundant. > Here's a concrete example: (pcase '(1 2 3 4) (`(,x ,y . ,z) `(,x ,y > . ,z))) is a no-op. In other words, q-patterns are equations with > multiple unknown variables (holes). When you write a q-pattern, > you're asking "what values should the variables in this pattern take > so that evaluating the pattern would return the matched data?" Normally, the pattern isn=E2=80=99t made related to the reuse of its var, b= ut related to the matched data, to look like it. Only then, by implication, you got it to look like what you would do to reconstruct it in the body. But that is a really interesting perspective I missed. Thank you for sharing it. This is the kind of implicit =E2=80=9Clogical=E2=80=9D intuiti= ve ideas that make designs meaningful that are kept unwritten, while they should, I believe, be advertised so to explain why a specific design is handy or natural (if ever newcomers found it unnatural).