From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel Subject: Re: The poor state of documentation of pcase like things. Date: Sat, 19 Dec 2015 22:25:51 +0000 Message-ID: <20151219222551.GB1899@acm.fritz.box> References: <20151216202605.GA3752@acm.fritz.box> <87fuyytq6b.fsf@web.de> <20151219183057.GA2238@acm.fritz.box> <871taimaqu.fsf@web.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1450563848 9195 80.91.229.3 (19 Dec 2015 22:24:08 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 19 Dec 2015 22:24:08 +0000 (UTC) Cc: emacs-devel@gnu.org To: Michael Heerdegen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Dec 19 23:24:00 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 1aAPux-0001Or-U3 for ged-emacs-devel@m.gmane.org; Sat, 19 Dec 2015 23:24:00 +0100 Original-Received: from localhost ([::1]:38933 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aAPux-0006FC-AE for ged-emacs-devel@m.gmane.org; Sat, 19 Dec 2015 17:23:59 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60837) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aAPuj-0006F3-NO for emacs-devel@gnu.org; Sat, 19 Dec 2015 17:23:47 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aAPue-0002IV-N4 for emacs-devel@gnu.org; Sat, 19 Dec 2015 17:23:45 -0500 Original-Received: from mail.muc.de ([193.149.48.3]:33259) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aAPue-0002IR-DM for emacs-devel@gnu.org; Sat, 19 Dec 2015 17:23:40 -0500 Original-Received: (qmail 51039 invoked by uid 3782); 19 Dec 2015 22:23:38 -0000 Original-Received: from acm.muc.de (p5B146D78.dip0.t-ipconnect.de [91.20.109.120]) by colin.muc.de (tmda-ofmipd) with ESMTP; Sat, 19 Dec 2015 23:23:36 +0100 Original-Received: (qmail 3920 invoked by uid 1000); 19 Dec 2015 22:25:51 -0000 Content-Disposition: inline In-Reply-To: <871taimaqu.fsf@web.de> User-Agent: Mutt/1.5.23 (2014-03-12) X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x X-Received-From: 193.149.48.3 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:196535 Archived-At: Hello, Michael. On Sat, Dec 19, 2015 at 09:42:01PM +0100, Michael Heerdegen wrote: > Alan Mackenzie writes: > > I wish you a happy one, though. > You too! Thanks! > > > As far as I understand how Stefan used to work, most of the semantics of > > > most of the pcase derivatives, like `pcase-let', are not yet 100% fixed, > > > we are not yet sure how useful we are, or if they may later be better be > > > replaced by other forms that are more general, etc. > > Yet the said functions have been committed on the release branch > I think Stefan used the term "don't advertise them yet too much" for > such things. > > and are already in widespread use throughout the Emacs sources. As > > Eli notes, there're around 90 uses of pcase-let and pcase-let*. > Could be they have nearly all been placed there by Stefan ;-) I think that's probable rather than possible. > > They're essentially undocumented. That makes the code that uses them > > essentially unmaintainable, except by those who know, or are prepared to > > guess, what these functions do. I can't agree with you that this is > > good. > This can't be the final state, no doubt. It must be fixed. Glad you agree. > But we have to do it very carefully, and maybe not completely now: if > even Stefan was not sure everywhere what could be written in the > documentation and if the code makes much sense, let's not engrave in > stone details we are not sure about whether they are true or intended or > useful. I don't really know what pcase-let does. I haven't a clue what pcase-lambda, pcase-defmacro, ... do. > This does not so much apply to `pcase-let' - I think it's quite clear > what it does, though I didn't use it often myself. It's not clear to me. I resent being forced to guess, read the pcase.el source, or give up on trying to understand significant portions of the Emacs source code. So, yes, I think `pcase-let' should be documented. > OTOH, I'm not so sure about `pcase-lambda' for example. How does/should > a `pcase-lambda' behave when applied to something that it's "signature" > doesn't match? Is it maybe cleaner to move a pcase call just inside the > `lambda'? Is the semantics of pcase really the best thing one can use > to hook pattern matching into a function, or is there a better one? In > practice, only a subset of pcase semantics makes sense for > `pcase-lambda' most of the time (mostly, destructuring), you can have > "only one clause" contrary to `pcase' - is the resulting code readable?; > is `pcase-lambda' a good abstraction/idea? If later we find it's a bad > idea, it's not good if we advertise it too much in the manual, because > we can't remove it so easily then. > > The pcase docstring is getting better, yes. It stil doesn't document > > explicitly that the normal meanings of ` and , are suspended. > Mmh, but it also doesn't say that the normal meanings of and, or, ' and > let are suspended. Good point. Perhaps it should say that about these symbols, too. And perhaps the entries in the Elisp manual for `and', `or', ``', `,', etc. should warn about the non-uniform meanings within pcase. The notion of kicking a wasp's nest springs to mind. > I think it doesn't have to, because a pcase pattern is not an > expression that is evaluated, so symbols with known names can't have > the same semantics as a pattern than as a defined function. That would be a good argument if only experts read the doc string. Thoroughly confused people also read doc strings. I don't think we should presuppose such sophisticated discernment in the typical reader. > > There is still no explicit statement of what pcase's ` and , mean. > But do we agree that the current docstring completely explains the > semantics, even if the definition is recursive? I don't agree. Completely missing is something like "pcase compares the value with each pattern in turn until one matches, and it then evaluates the corresponding BODY, returning the result of the last body form evaluated. If no pattern matches, nil is returned.". The somewhat offensive "perform ML-style pattern matching on that value" is no substitute for this. There is no mention of ``' and `,' in the section on patterns. Or is \\='VAL really meant to be \\=`VAL? > > Maybe I'm expecting too much, and ` and , have no intrinsic meanings in > > pcase. But I don't believe that is the case. > ``' is a pcase macro (at least now). pcase macros are like Lisp macros, > but while Lisp macros expand to Lisp code, pcase macros expand to pcase > patterns. > The backquote macro ``' in Lisp is a utility that is used to build > lists. pcase's ``' is used to build patterns that match lists. The > only difference for unquoting (`,'), so to say, is that in the first > case it "inserts" an arbitrary "value" at that position, and in the > second case, "inserts" an arbitrary pcase pattern (that is responsible to > match the element at that place, instead of being a specified constant > that matches only itself via `equal'.) But what does ``' _do_? What it normally does is well explained in its own doc string (which will need modification for pcase). But what does ``' _do_ within pcase? Saying "it is used to build patterns ...." is a cop out. The difficulty in describing its (and `,''s) semantics seems to be a weakness in pcase. > If you only unquote symbols, like in > `(1 2 ,x) > you can imagine that x is already bound to the "right" value, then the > thing works much like the standard backquote. That analogy is not so > useful for things like > `(1 2 ,(pred stringp)) > I guess, though you still can imagine that the pattern matches any > three-element list whose first two elements are 1, 2, and as third > element, anything that fulfills the predicate "stringp" can be > "inserted". > You can verify by yourself that elements in a backquoted list in pcase > "behave" as if they were quoted with a quote (see the 'VAL form) - thus > the name "QPattern" - and that the rules for quoted atoms apply as > expected, and such things. Are you saying that "QPattern" has no more conceptual meaning than "patterns which are backquoted"? > [ While writing this, I see now that the doc of ``' in the pcase doc is > a typical mathematical definition: it is absolutely correct, but > doesn't say "what it's good for" and "how to use it". To be honest I > also had much trouble to understand it when I learned `pcase'. ] I think I've got some reasonable partial understanding of ``', but I'm unhappy that there's no concise description of what it does. > BTW, there is no `,@' unquote splicing in pcase's backquote because it > can lead to ambiguity when matching (and would be slow). OK. > Regards, > Michael. -- Alan Mackenzie (Nuremberg, Germany).