From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michael Heerdegen Newsgroups: gmane.emacs.devel Subject: Re: Update of pcase docs for the elisp manual Date: Mon, 25 Jan 2016 15:15:14 +0100 Message-ID: <878u3drbil.fsf@web.de> References: <87d1stznc6.fsf@web.de> <83io2k5yvg.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1453731457 9119 80.91.229.3 (25 Jan 2016 14:17:37 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 25 Jan 2016 14:17:37 +0000 (UTC) Cc: John Wiegley , emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Jan 25 15:17:27 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aNhxP-0005NE-55 for ged-emacs-devel@m.gmane.org; Mon, 25 Jan 2016 15:17:27 +0100 Original-Received: from localhost ([::1]:38880 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aNhxO-0002Gr-2t for ged-emacs-devel@m.gmane.org; Mon, 25 Jan 2016 09:17:26 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38787) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aNhvO-00081i-Mo for emacs-devel@gnu.org; Mon, 25 Jan 2016 09:15:24 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aNhvJ-0000B3-LN for emacs-devel@gnu.org; Mon, 25 Jan 2016 09:15:22 -0500 Original-Received: from mout.web.de ([212.227.17.12]:54575) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aNhvJ-0000Aw-Bl; Mon, 25 Jan 2016 09:15:17 -0500 Original-Received: from drachen.dragon ([92.77.162.209]) by smtp.web.de (mrweb103) with ESMTPSA (Nemesis) id 0LiUKG-1ZpjYN2tBM-00cfxK; Mon, 25 Jan 2016 15:15:15 +0100 In-Reply-To: <83io2k5yvg.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 23 Jan 2016 13:17:07 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) X-Provags-ID: V03:K0:FllTy9mevJtaGhXi/GoGkFcJWRmU3u/TMhjsgRwXS/pKnr/NGSA GU9Vr1SQ0zmK/l+PRUnvncN8JLx/ARDR19WkZmF50/RcLqm5aGAha53mn0ZifwyRcVAJLSt THGGxlBIWF3nmuooXBgjM/1KHOQNSQlayWgo3ZLnqNuHByH6XFb4l5sqRAatqithcGkmnTn sW24Ekt1dKFrf9uw2Dydg== X-UI-Out-Filterresults: notjunk:1;V01:K0:ffqDJeq8Dsg=:zRlRfTHUTi7liqJiEL161Q tQzyThiG1pfANkXwLBNrgY1zqrBVitT5M+9kxYC+0Ym7g/0Yh2qbdClBKivjmDNYmnAmd7rO5 9bpkKqmL9+4eckYU7Ptf9imKwupsv0RVJ3PoBcsL3rWIUyv9XSyYN4tcYoqUrSMC5ophyB7k/ yrl0jIhHVMMx/zQBP1owicxorq9RUeQUGD1Mk5jcZJyCYSFZcw2cL524yVKgfBrsz1mdC5qgq J9q6DT77xjQYafk3e89AooX9SH2DzIP07Swuv4mQKRw1w9btWkVOU/ujzFCXZ5dPUHW6NZI1c kED9QEUz7U+AIGeJzGQCI8N3OO2Zz83lI+bR72EdvRzRM4SoIQxwi/jIl44EFU1dtOxP3S1EG DL1ZkSfX+kRultYI/V7E5goSs4V1K8q470DEEQn8Bt1Ymp1JPcPuGDrbeiOZUjnBKwbt4Eg3R zYCxi9T5uji1+vLk0yvfMzb552lzfbjGaDUG/Lc/+I2i1O4Xk4f7CPOWedIvPXqMR2e3WwCRW hp+FdmwdDKbq0zgnwhYTjAp7d4WMxmJhSQ5TXGuOlLcgdg0atyQy7mqszBWI9vJbqY7fWcTYR fL+ZaCS3mvORIc2DQ6USSGD+1J2Ew/t0tQ+s4lCP5tPIvnWn2sVHtYxyX3t+dtowLX3fqOBAU 590c4URXYQUWS9Ja6C5OKlVb7gUo8KOt5MPYoUIc/eewI3RB977lT3i9+zOzwcVM9jrUBlkJy pEMEcPlDW/DbcGUpauk4XsKmGC65Qm600H6C/8/CTgF1GlEmslEVnUZHlQl5v5jWdRs+N3/l X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.17.12 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 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-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:198763 Archived-At: Eli Zaretskii writes: > . The description of the 'let' pattern is not entirely clear. > Michael's examples actually confused me instead of helping to > understand it, because the examples use the same symbol for the > 1st arg of 'pcase' and for symbols that are UPatterns (and also in > other contexts). Example: > > (pcase x > ((and (pred numberp) > (let (pred (lambda (x) (< 5 x))) > (abs x))) > t) > (_ nil)) > > The documentation of 'let' says that it matches if the expression > matches the pattern. Here, the expression is "(abs x)" and the > pattern is "(pred (lambda (x) (< 5 x)))", right? Yes. > So how can they "match"? The fact that 'x' is used here in no > less than 3 different contexts doesn't help, either. I actually > don't understand the "(abs x)" part at all, since 'x' was not > bound to anything by any previous pattern. AFAIU, the 1st > argument of 'pcase' cannot be used like that, because it will not > be a symbol in the general case, it's an expression whose value is > not bound to anything. That's all correct. Though, if we test the value of the variable `x' with pcase, this makes only sense if `x' is bound. And we made a `numberp' test quite before, so the expression (abs x) makes sense, and is "in the same context as `x' tested expression. That the lambda in the `pred' uses x as a new global variable is bad indeed, we should use a different name. Dunno if it's a good example at all. But since just binding a symbol is better done with just SYMBOL as pattern, I wanted to provide an example that shows a different use case. > The sharp-eyed among you might notice that the documentation of > the 'let' pattern is somewhat vague -- the above is the reason. Sorry, I've lost my orientation. What is the reason? > . The exact syntax and possible forms of QPatterns are described > ambiguously and seemingly incompletely, and profoundly contradict > almost every given example of them. Both Michael and the previous > manual text describe them as follows: > > The form is `QPAT where QPAT is one of the following: > > (QPAT1 . QPAT2) > [QPAT1 QPAT2 ... QPATn] > ,PAT > ATOM > > The last two look wrong: AFAIU, there is no QPattern of the form > `,PATH or `ATOM. These 2 seem to be _components_ or QPatterns, > see below. Did Stefan make it clear for you? > . Many of the examples using QPatterns seem to allow to be easily > rewritten to use only UPatterns, by adding additional 'pred' and > 'guard' conditions. Is that true? If so, we should tell this > somewhere, because otherwise the reader might think she > misunderstood something very important. I did, because none of > the texts I've seen in preparation for this work discusses this > aspect. Take this, for example: > > (pcase x > (`("foo") t) > (`("foo" ,a) a) > (`("foo" . ,(and (pred listp) rest)) rest)) > > What do we have here that cannot be done with UPatterns? How would you rewrite `("foo" . ,(and (pred listp) rest)) using only Upatterns? The shortest way would probably look like this: (and (pred consp) (app car "foo") (app cdr (and (pred listp) rest))) Everything involving QPatterns can be expressed without them. So I'm not sure what you mean. Thanks, Michael.