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: The poor state of documentation of pcase like things. Date: Sat, 19 Dec 2015 16:55:12 +0100 Message-ID: <8737uytov3.fsf@web.de> References: <20151216202605.GA3752@acm.fritz.box> <83d1u4xhja.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1450540555 1710 80.91.229.3 (19 Dec 2015 15:55:55 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 19 Dec 2015 15:55:55 +0000 (UTC) Cc: kaushal.modi@gmail.com, John Wiegley , emacs-devel@gnu.org, acm@muc.de To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Dec 19 16:55:47 2015 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 1aAJrF-0005Kf-Td for ged-emacs-devel@m.gmane.org; Sat, 19 Dec 2015 16:55:46 +0100 Original-Received: from localhost ([::1]:37746 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aAJrE-00067v-Pn for ged-emacs-devel@m.gmane.org; Sat, 19 Dec 2015 10:55:44 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33898) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aAJqs-00066k-Mq for emacs-devel@gnu.org; Sat, 19 Dec 2015 10:55:23 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aAJqr-0006x4-Lv for emacs-devel@gnu.org; Sat, 19 Dec 2015 10:55:22 -0500 Original-Received: from mout.web.de ([212.227.17.11]:60056) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aAJqn-0006wG-Q2; Sat, 19 Dec 2015 10:55:18 -0500 Original-Received: from drachen.dragon ([90.186.0.107]) by smtp.web.de (mrweb103) with ESMTPSA (Nemesis) id 0LfiuU-1aZ98z2iba-00pImT; Sat, 19 Dec 2015 16:55:16 +0100 In-Reply-To: <83d1u4xhja.fsf@gnu.org> (Eli Zaretskii's message of "Fri, 18 Dec 2015 10:55:21 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) X-Provags-ID: V03:K0:hGewkjdQ/Fwbv97vhLFuq/+AHOTe8bhjA1ou34ytYbWgWxAhFKe J969kKnQ6I7vTVkEzROmXl0ASNHxORMcJhPysZYR2eHVhULr4MXSUikDNAyFgSXsG57uWIq Yxi+KP8LRqXgH/3xtQ+7rQMnnR5WEBF48gbLcQaRFrY1B1z85+JWD9ixwXYI1N24+V8k36G ETfnoBAteEXPc2Q7Obdvw== X-UI-Out-Filterresults: notjunk:1;V01:K0:og9R2LkaHEo=:rCG/6unp2Crdr8pa8NEIu7 1aFajftF512lqoS+2sjkUnsHMgdwYNrEkZA1EGU+m4n28fJA0nZN/JeiSjEag4kyLslmQeH9C XygBkovRbdHhMXgddGiB5+D6TH9ln5p8pu5/nz+u3MRL01jTvHkoezaGHhFkN5iYOLXh8NLTq mKqwr3kZMyYNbxCb1Htfzsr7vunDUD9N95UrEBKmKC9kCrWo9uvlUTxcmZmxJ4RwnwxnUgRU1 E1E0huDBsi+2RZBgIQLNq5tarodkfa+tqjutHJ+TjPjCTsMEz/B/rameGMoAjjEplXULclN3b eqcVeJtKn2s4GutavInynbyH6TBUj3e0qRieMiDdr/cR+y0KXoPDO0BpNxDW9bnHMobfYpM8U Q4QWK/spES6lp/6pOYdveWYrTevsGHJYLEKigvA/XShTKQHWhfkWAFZz6o6pETuGjU+35zgYa iaTBksOPV6uXsq2/r4ppJ52vJ1oGUlT3qSmItVr5AJVV9+zRsPgAYPDZ7bNDG+3kUk7pBzFKa Fjsv3T/MBzOgEu54TTNntKSa5wtlxSwXToxRTCxZ8HRbHpoyCE+boFzO7sy/8FbKPurUFfvdu TdRribnh87+PIS741EXoyacx15iE9N01MfR7RgnTBqI7ZBIh/EGS8GMQHEhYECHmiUKBOycHJ 8hj770q1m0KbAikZMs+TNGZnEDHBwlqe8g7ShdHOMUCdW0bkUp98VVEz581npfrLOKCM36JVK NcYwCXB3mCoecrsG+YrqFfGp72fycVNbbV+U5ItMG0zHrtqwIIjLZ59WTgnRgf27BRLV6EJT X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.17.11 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:196508 Archived-At: Eli Zaretskii writes: > But the example doesn't use `,foo`, it uses just ,foo. I guess `..` > here is some markdown-style "quoting", unrelated to the Lisp > backticks? Yes. > "Local symbol" here meaning what? an un-interned symbol or a local > variable by that name? It binds to the symbol specified. The type of binding is local. > > (pcase value > > (`(1 2 ,foo 3) > > (message "Matched 1, 2, something now bound to foo, and 3")) > > (foo > > (message "Match anything at all, and bind it to foo!")) > > (`(,the-car . ,the-cdr)) > > (message "Match any cons cell, binding the car and cdr locally")) > > So to bind something to 'foo' you just use "foo", but to bind > something to 'the-car' and 'the-cdr' you need to use ",the-car" and > ",the-cdr"? Why the inconsistency? The examples only differ because some symbols occur inside backquote and others don't. > > The reason for doing this is two-fold: Either to refer to a previous match > > later in the pattern (where it is compared using `eq'), or to make use of a > > matched value within the related code block: > > > > (pcase value > > (`(1 2 ,foo ,foo 3) > > (message "Matched (1 2 %s %s 3)" foo))) > > ??? Is "foo" here bound to 2 different values? And how come the > format has 2 %s, but only one variable, foo, to provide values? The second occurrence is turned into an equivalence test (the pcase docstring does already say that). The message call is invalid. > > We can express boolean logic within a pattern match using the `or` and `and` > > Patterns: > > > > (pcase value > > (`(1 2 ,(or 3 4) > > ,(and (pred stringp) > > (pred (string> "aaa")) > > (pred (lambda (x) (> (length x) 10))))) > > (message "Matched 1, 2, 3 or 4, and a long string " > > "that is lexically greater than 'aaa'"))) > > Why did you use 'lambda' for the 3rd predicate, but not for the 2nd? > Is it just a way to show off use of 'lambda', or is there some > significant difference between these 2 use cases that requires a > 'lambda' in the latter case? More generally, when is 'lambda' > required in a predicate like these ones? That's explained in the pcase docstring. > Isn't it true that pcase-let is just a short-hand for a pcase that > assigns values according to patterns, and has nil as the default > value? If that's true, I think it explains better what pcase-let > does, especially when backed up by an example of a pcase and the > equivalent pcase-let. I think there are more differences, AFAICT pcase-let can't "fail", and it can bind multiple value--pattern pairs. Michael.