From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Michael Heerdegen Newsgroups: gmane.emacs.devel Subject: Re: Replace trivial pcase occurrences in the Emacs sources Date: Sat, 03 Nov 2018 18:12:43 +0100 Message-ID: <87efc22igk.fsf@web.de> References: <83r2g8klf9.fsf@gnu.org> <83wopzk3sw.fsf@gnu.org> <83r2g7jrot.fsf@gnu.org> <83k1lzjq0r.fsf@gnu.org> <83in1jjmy4.fsf@gnu.org> <20181031120821.GA20575@ACM> <831s86jey9.fsf@gnu.org> <83wopue1xl.fsf@gnu.org> <87o9b62mij.fsf@web.de> <83sh0idt6m.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1541265100 30227 195.159.176.226 (3 Nov 2018 17:11:40 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 3 Nov 2018 17:11:40 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: monnier@iro.umontreal.ca, emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Nov 03 18:11:36 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 1gIzSS-0007kz-9k for ged-emacs-devel@m.gmane.org; Sat, 03 Nov 2018 18:11:36 +0100 Original-Received: from localhost ([::1]:56323 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gIzUY-0005Fh-Ga for ged-emacs-devel@m.gmane.org; Sat, 03 Nov 2018 13:13:46 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:37409) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gIzTu-0005EJ-87 for emacs-devel@gnu.org; Sat, 03 Nov 2018 13:13:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gIzTq-0003j3-7y for emacs-devel@gnu.org; Sat, 03 Nov 2018 13:13:06 -0400 Original-Received: from mout.web.de ([217.72.192.78]:43683) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gIzTm-0003TL-6G; Sat, 03 Nov 2018 13:13:00 -0400 Original-Received: from drachen.dragon ([94.218.210.177]) by smtp.web.de (mrweb101 [213.165.67.124]) with ESMTPSA (Nemesis) id 0LcPf8-1frvvn12JC-00jmlE; Sat, 03 Nov 2018 18:12:45 +0100 Original-Received: from drachen.dragon ([94.218.210.177]) by smtp.web.de (mrweb101 [213.165.67.124]) with ESMTPSA (Nemesis) id 0LcPf8-1frvvn12JC-00jmlE; Sat, 03 Nov 2018 18:12:45 +0100 In-Reply-To: <83sh0idt6m.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 03 Nov 2018 18:25:37 +0200") X-Provags-ID: V03:K1:VyE/zcsmYshhxrNN0BBS4lwBDOCDaSKK4cQYXemY+SDX3FMrDWU NCpMWA4w0HkfzPt4CxnwLnEQPEHAQIrW3Eih3L9VT7rq9L0C0aYtu+2hag9OF2bwWyyz+G2 wuhZ0q5Z63T1ZQ9dXZeeK65y2laU9bdI84IT4TVna49piisisUlvB/LnST9Ij15pdnsIYXP 4V1WNd1D4vqDYC31kj3Fg== X-UI-Out-Filterresults: notjunk:1;V01:K0:PpZrRDbTG/s=:T8K3fO63gZMnxwCOaWo/qM Ri1UyyRxvAsqcfexL1Pire3CzLpLzp1SXP8uLyqTHBmeNSFwNKNUQMHv4A41yQXxFPXowCK2q cPC/odTCfee1kr+ojgCUd806ss0K05WmWnu5xicQQjQ6JQBvPClP+IxpWL8Gzfah6je7T5+BV hpyDko5ruXQG8MHBy/ruvhm9MEX3O4iI/ce9N8qSEPW/7edX+EAra1B00bmb75GSx35cKb6Zq uRzC2AmbITZpj9oqZmlAylOJfYOKgKww87L3CSK9pI5V90dNPkoxThXmjVo/UYp1KedQ5BgEj rYGRSkrrnik9MpyFtz8fkIclxC+XMosj/z5swJOR8luB8UgpUP/EjV2KCUB1ebZYwGeMvjdhe eRsAiDmH00v5FTGQZsnZtjDV1lyu5ZSH/KJMiSuPcnlsIqF8Zuo7uJQlWZ7k36iRCELXDF3Be 3vLLd1QoDaln+Ryjcb+xf4jmrLPpA3L6lqphy9YjEjlRxEeunoLT0BvnTfTLzS2neWReJderb hyWvTnSXIROc8nzdD4+v7Yu7apjMJpUh6WjvKVFtzoZL5iglEbeX3+dIxq7JfPJsInM3B84VJ SVocoO6odx/VoDIpdyH2sq/uCAI6+cvJz9EKaCc8aN6o7X9fTsVcqD2KZtNXoEcejbqJzK6AZ rxQ+HYLZtGkWZpkgbojanoFkTtVyGbzdQjXbxry4iIB9Uz/mO8dNmXoku96IQLwI+wFythgLx AkFY04IItjvM1HokHyQbkyQFK7KFbItsX1EbaW66XadcKCrp+/q6NfsLhCnAlBqwP7u5FnYw X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 217.72.192.78 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:230995 Archived-At: Eli Zaretskii writes: > > | The pcase patterns that are useful for destructuring bindings are > > | generally those described in @ref{Backquote Patterns}, since they > > | express a specification of the structure of objects that will match. > > > > I don't like that sentence for two reasons: > > > > (1) ` is the pcase pattern for destructuring. The "Backquote Patterns" > > or "Backquote style Patterns" are not really "pcase patterns" since > > they > > are part of the implicit semantics ``' defines. They are _not_ pcase > > patterns. Your sentence confuses the both. > > Sorry, you lost me here. How can these not be pcase patterns, when > they are used with 'pcase', and "pcase patterns" are _defined_ as > those used with 'pcase'? We called these UPATS in the past btw. Not every part of a pattern is also a pattern. ,a is not an expression since it's only valid as sexp inside a backquote expression. For a similar reason, ,a is not a pcase pattern because it's only valid in a ` pattern. (< 1) is also not a pcase pattern, although it's valid inside a pred: (pred (< 1)). A pcase pattern should only be called what is valid as PATTERN in a pcase clause (PATTERN BODY). > > (2) We already have a lot other patterns for destructuring (eieio, seq, > > map, cl-struct), and we probably will get even more in the future. > > OK, but why is that a reason not to use what I wrote? Note that it > talks about "destructuring binding", not just about destructuring. Well, for binding there is only one pattern, SYMBOL. But you also write | since they express a specification of the structure of objects that | will match. so this seems to speak about destructuring and not about binding. > Also please note that I made some changes in the description of > seq-let to say that is an alternative facility for destructuring > binding. > > The text you quoted doesn't say that those pcase patterns are the > _only_ method of destructuring. If that is the root cause of your > disliking, we could make this even more clear. I didn't speak about other methods in Emacs, I spoke about other pcase patterns also performing destructuring. But | The pcase patterns that are useful for destructuring bindings are | generally those described in @ref{Backquote Patterns} makes it sounds if ` is the only method to get destructuring bindings with pcase. > > | @defmac pcase-let bindings body@dots{} > > | Perform desctructuring binding of variables according to > > | @var{bindings}, and then evaluate @var{body}. > > > > and lots of similar: > > > > `pcase-let', `pcase-dolist' and the like are very often used only for > > destructuring, but they are not limited to destructuring. Like in > > > > (defun test (arg) > > (pcase-let (((or (and (pred stringp) s) > > (and (pred numberp) (app number-to-string s))) > > arg)) > > s)) > > > > (test "Hallo") => "Hallo" > > (test 1) => "1" > > OK, but why would I need pcase-let in this example? Isn't the above > the same as > > (defun test (arg) > (let ((s (cond ((stringp arg) arg) > ((numberp arg) (number-to-string arg))))) > s)) > > (which is both simpler and shorter)? It was just an example. And docstrings shouldn't tell restrictions that don't exist just because you would prefer `cond' in such cases anyway. > > Also the docstrings give the impression that these are limited to > > destructuring, which is not true. > > Can you tell where did you get that impression? The doc strings talk > about destructuring bindings, when BINDINGS have the form specified, > and I believe that is true. You say | Perform desctructuring binding of variables according to | @var{bindings}, and then evaluate @var{body}. Any pcase PATTERN can be used in BINDINGS, whether it performs destructuring or not, the only assumption is that it should match. You can say that pcase-let is mostly useful for destructuring the bound values, but as a summary of what `pcase-let' and the like is about it's misleading. It's misleading because I then wonder where the restriction to destructuring comes from, and what's different to just matching the patterns against the values as in `pcase'. Michael.