From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: phillip.lord@russet.org.uk (Phillip Lord) Newsgroups: gmane.emacs.devel Subject: Re: The poor state of documentation of pcase like things. Date: Fri, 18 Dec 2015 10:39:27 +0000 Message-ID: <87mvt859cw.fsf@russet.org.uk> References: <20151216202605.GA3752@acm.fritz.box> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1450435193 24254 80.91.229.3 (18 Dec 2015 10:39:53 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 18 Dec 2015 10:39:53 +0000 (UTC) Cc: kaushal.modi@gmail.com, John Wiegley , emacs-devel@gnu.org, acm@muc.de To: Richard Stallman Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Dec 18 11:39:51 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 1a9sRz-0007LJ-34 for ged-emacs-devel@m.gmane.org; Fri, 18 Dec 2015 11:39:51 +0100 Original-Received: from localhost ([::1]:59486 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9sRy-0005FT-Cu for ged-emacs-devel@m.gmane.org; Fri, 18 Dec 2015 05:39:50 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50836) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9sRk-0005FA-1R for emacs-devel@gnu.org; Fri, 18 Dec 2015 05:39:37 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a9sRj-0006ay-6Z for emacs-devel@gnu.org; Fri, 18 Dec 2015 05:39:35 -0500 Original-Received: from cheviot22.ncl.ac.uk ([128.240.234.22]:52867) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9sRd-0006Yh-8j; Fri, 18 Dec 2015 05:39:29 -0500 Original-Received: from smtpauth-vm.ncl.ac.uk ([10.8.233.129] helo=smtpauth.ncl.ac.uk) by cheviot22.ncl.ac.uk with esmtp (Exim 4.63) (envelope-from ) id 1a9sRb-0007Er-EI; Fri, 18 Dec 2015 10:39:27 +0000 Original-Received: from jangai.ncl.ac.uk ([10.66.67.223] helo=localhost) by smtpauth.ncl.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.63) (envelope-from ) id 1a9sRb-00058y-9w; Fri, 18 Dec 2015 10:39:27 +0000 In-Reply-To: (Richard Stallman's message of "Thu, 17 Dec 2015 23:07:53 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 128.240.234.22 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:196462 Archived-At: Richard Stallman writes: > [[[ To any NSA and FBI agents reading my email: please consider ]]] > [[[ whether defending the US Constitution against all enemies, ]]] > [[[ foreign or domestic, requires you to follow Snowden's example. ]]] > > > There are many special UPatterns, and their variety makes this the hardest > > aspect to master. Let's consider them one by one. > > > ## Underscore `_' > > > To match against anything whatsoever, no matter its type or value, use > > underscore. Thus to match against a list containing anything at all at its > > head, we'd use: > > > (pcase value > > (`(_ 1 2) > > (message "Matched a list of anything followed by (2 3)"))) > > I don't follow this part. (_ 1 2) seems to be a QPattern. > Is that right? So how is it that an element can be a UPattern? I think the example is wrong. This.... (pcase '(3 1 2) (`(_ 1 2) (message "Matched a list of anything followed by (2 3)"))) prints nothing. while this... (pcase '(3 1 2) (`(,_ 1 2) (message "Matched a list of anything followed by (2 3)"))) prints the message (which should be "followed by (2 3)"). I am a bit surprised to find that _ needs , in these examples, and I think that it's a bug. I would anyway change it to: (pcase '(3 1 2) (`(,_ 1 2) "Matched a list of anything followed by (1 2)")) As I think it makes the point that `pcase' returns something, as opposed to working by side effect. I think the example in the manual needs the same change. > It would help if some of the examples used symbols inside a QPattern, > without comma, so we can see what that does. A symbol IS a QPattern (pcase '(a b c) (`(a b ,x) x)) returns "c". Phil