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: pcase docs Date: Sat, 23 Jan 2016 16:50:04 +0200 Message-ID: <83y4bg4ag3.fsf@gnu.org> References: <83a8o8gcya.fsf@gnu.org> <87zivx5ree.fsf@web.de> <87r3h95qs3.fsf@web.de> <83wpr15mk1.fsf@gnu.org> <8737toiota.fsf@web.de> <83fuxo5xo4.fsf@gnu.org> <87mvrwzekd.fsf@web.de> <8360yk5sgm.fsf@gnu.org> <87vb6k8jfz.fsf@web.de> Reply-To: Eli Zaretskii NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1453560603 15448 80.91.229.3 (23 Jan 2016 14:50:03 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 23 Jan 2016 14:50:03 +0000 (UTC) Cc: jwiegley@gmail.com, emacs-devel@gnu.org To: Michael Heerdegen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Jan 23 15:49:57 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 1aMzVi-0004NN-Kd for ged-emacs-devel@m.gmane.org; Sat, 23 Jan 2016 15:49:54 +0100 Original-Received: from localhost ([::1]:57670 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMzVh-0002RG-CV for ged-emacs-devel@m.gmane.org; Sat, 23 Jan 2016 09:49:53 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48686) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMzVd-0002QM-5z for emacs-devel@gnu.org; Sat, 23 Jan 2016 09:49:50 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aMzVZ-0002ED-1t for emacs-devel@gnu.org; Sat, 23 Jan 2016 09:49:49 -0500 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:50214) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMzVY-0002E9-Uf; Sat, 23 Jan 2016 09:49:44 -0500 Original-Received: from 84.94.185.246.cable.012.net.il ([84.94.185.246]:2253 helo=HOME-C4E4A596F7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1aMzVY-0001vC-1x; Sat, 23 Jan 2016 09:49:44 -0500 In-reply-to: <87vb6k8jfz.fsf@web.de> (message from Michael Heerdegen on Sat, 23 Jan 2016 15:22:08 +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:198644 Archived-At: > From: Michael Heerdegen > Cc: jwiegley@gmail.com, emacs-devel@gnu.org > Date: Sat, 23 Jan 2016 15:22:08 +0100 > > Eli Zaretskii writes: > > > > Surely not! I just had the time to read the code, carefully (I had to, > > > to be able to write my el-search.el thing). Most others don't care > > > because they just don't care, I think. > > > > But this stuff is widely used, by several different individuals. How > > do they know what to put in the code, if they, like me, are confused > > about the purpose and the usage? > > Dunno. If it helps: I had spent really a lot of time into understanding > pcase. More time than you can probably invest, doing all the work you > do. And I made lots of errors over weeks after had finally internalized > everything. So maybe we should drop everything and make sure those doc strings are corrected? > > > Actually `pcase-defmacro' is easy to understand if you understood > > > `defmacro': You define a pattern by its name and by the arguments it > > > will accept. > > > > But 'pcase' patterns don't accept any arguments, they are matched > > against a value of an expression. So how to understand "arguments" in > > this context? > > pcase-defmacro can only define patterns that are used like function > calls, (pattern-name pattern-args), like > > > (pred fun) > (guard expr) > (or pattern...) > > In the sense of pcase-defmacro, FUN, EXPR or the PATTERNs play the role > of arguments of the pattern. I don't think I see any of this in the doc string... > > And how to explain that a pattern that starts with "`(list" will > > somehow end up using the pattern defined with "(pcase-defmacro map"? > > No, `map' doesn't define `, it defines a pattern named `map' (that > currently is rarely used, or nowhere). That's the problem: that the pattern 'map' is not used. Instead, I see its sub-classes being used as pcase patterns. > (pcase-defmacro greater-than (number) > `(and (pred numberp) > (pred (lambda (x) (< ,number x))))) > > Then any occurrence of (greater-than N) in any pcase pattern is simply > substituted with > > (and (pred numberp) > (pred (lambda (x) (< N x)))) > > That's it. That's what I expected to see when I saw this: (pcase-defmacro map (&rest args) I expected to see its use like this: (map SOMETHING) But instead I see this: (pcase type (`list (map-pairs map)) (`hash-table (map--into-hash-table map)) (_ (error "Not a map type name: %S" type)))) IOW, there's no 'map', which was defined with pcase-defmacro, but there are 'list' and 'hash-table', which weren't. And btw, why "`list" instead of "`(list"?