From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Replace trivial pcase occurrences in the Emacs sources Date: Mon, 29 Oct 2018 17:08:38 -0400 Message-ID: References: <83tvlcsnee.fsf@gnu.org> <86mur137n8.fsf@gmail.com> <20181029130132.GB4195@ACM> <20181029134722.GC4195@ACM> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1540847218 26549 195.159.176.226 (29 Oct 2018 21:06:58 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 29 Oct 2018 21:06:58 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Oct 29 22:06:54 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gHEkQ-0006nf-1r for ged-emacs-devel@m.gmane.org; Mon, 29 Oct 2018 22:06:54 +0100 Original-Received: from localhost ([::1]:48957 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHEmW-0003ms-Ki for ged-emacs-devel@m.gmane.org; Mon, 29 Oct 2018 17:09:04 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40042) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHEmQ-0003mX-CQ for emacs-devel@gnu.org; Mon, 29 Oct 2018 17:08:59 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHEmL-0001nE-Fc for emacs-devel@gnu.org; Mon, 29 Oct 2018 17:08:58 -0400 Original-Received: from [195.159.176.226] (port=39297 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHEmL-0001mX-8G for emacs-devel@gnu.org; Mon, 29 Oct 2018 17:08:53 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1gHEk9-0006Ua-9h for emacs-devel@gnu.org; Mon, 29 Oct 2018 22:06:37 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 48 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:a5wKWr4lNhT9RiZPi+uFVrpyI0g= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 195.159.176.226 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 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" Xref: news.gmane.org gmane.emacs.devel:230770 Archived-At: >> > Doc strings which specify fully the arguments to these macros, including >> > their semantics, and say what the macros do. The current doc strings >> > (at least some of them) for these macros don't do this. >> I understand this in theory, but I don't know what it means in this >> concrete case. > Take a look at, for example, the doc string for pcase-dolist. In its > entirety, it's this: Thanks. What do you think of the patch below? I'd rather keep it defined in terms of its differences w.r.t `dolist`, but if really needed, we could change the doc so it doesn't rely on `dolist`s own doc at all. We do have to keep the reference to `pcase` because we don't want to repeat the definition of what a pcase pattern can look like. Stefan diff --git a/lisp/emacs-lisp/pcase.el b/lisp/emacs-lisp/pcase.el index 57c2d6c3cb..861c900b21 100644 --- a/lisp/emacs-lisp/pcase.el +++ b/lisp/emacs-lisp/pcase.el @@ -281,7 +281,7 @@ pcase-let* (defmacro pcase-let (bindings &rest body) "Like `let' but where you can use `pcase' patterns for bindings. BODY should be a list of expressions, and BINDINGS should be a list of bindings -of the form (PAT EXP). +of the form (PATTERN EXP). The macro is expanded and optimized under the assumption that those patterns *will* match, so a mismatch may go undetected or may cause any kind of error." @@ -302,7 +302,12 @@ pcase-let ;;;###autoload (defmacro pcase-dolist (spec &rest body) - "Like `dolist' but where the binding can be a `pcase' pattern. + "Superset of `dolist' where the VAR binding can be a `pcase' PATTERN. +More specifically `dolist's VAR binding is replaced by a PATTERN +against which each element of the list is matched. +As in the case of `pcase-let', PATTERN is matched under the assumption +that it *will* match. + \n(fn (PATTERN LIST) BODY...)" (declare (indent 1) (debug ((pcase-PAT form) body))) (if (pcase--trivial-upat-p (car spec))