From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: The poor state of documentation of pcase like things. Date: Sat, 19 Dec 2015 19:08:18 +0200 Message-ID: <83bn9mv01p.fsf@gnu.org> References: <20151216202605.GA3752@acm.fritz.box> <83d1u4xhja.fsf@gnu.org> <8737uytov3.fsf@web.de> Reply-To: Eli Zaretskii NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1450544897 7942 80.91.229.3 (19 Dec 2015 17:08:17 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 19 Dec 2015 17:08:17 +0000 (UTC) Cc: kaushal.modi@gmail.com, jwiegley@gmail.com, emacs-devel@gnu.org, acm@muc.de To: Michael Heerdegen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Dec 19 18:08:16 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 1aAKzO-0003Mu-R7 for ged-emacs-devel@m.gmane.org; Sat, 19 Dec 2015 18:08:14 +0100 Original-Received: from localhost ([::1]:38058 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aAKzN-0005ho-Uz for ged-emacs-devel@m.gmane.org; Sat, 19 Dec 2015 12:08:13 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49166) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aAKz8-0005fb-Gh for emacs-devel@gnu.org; Sat, 19 Dec 2015 12:07:59 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aAKz7-0006Sb-Ev for emacs-devel@gnu.org; Sat, 19 Dec 2015 12:07:58 -0500 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:43993) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aAKz3-0006OR-Qy; Sat, 19 Dec 2015 12:07:53 -0500 Original-Received: from 84.94.185.246.cable.012.net.il ([84.94.185.246]:3726 helo=HOME-C4E4A596F7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1aAKz2-0003kx-PA; Sat, 19 Dec 2015 12:07:53 -0500 In-reply-to: <8737uytov3.fsf@web.de> (message from Michael Heerdegen on Sat, 19 Dec 2015 16:55:12 +0100) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e 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:196514 Archived-At: > From: Michael Heerdegen > Cc: John Wiegley , acm@muc.de, emacs-devel@gnu.org, kaushal.modi@gmail.com > Date: Sat, 19 Dec 2015 16:55:12 +0100 > > > > (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. ",foo" in the first pattern is also inside a backquote, but it is still different from "foo" in the second pattern and ",the-car" in the third. So I'm still not out of the woods regarding the inconsistency. > > > (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. Which part of it? > > 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" Neither can a pcase that has a default clause, right? > and it can bind multiple value--pattern pairs. Did John's tutorial include an example of that? Or maybe I shouldn't ask about pcase-let, as it's not for the uninitiated yet? ;-)