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: Tue, 23 Oct 2018 14:12:34 -0400 Message-ID: References: <20151216202605.GA3752@acm.fritz.box> <83si2f9ve4.fsf@gnu.org> <56889EC3.3040108@yandex.ru> <877fjrkpdf.fsf@fencepost.gnu.org> <56892334.4000106@yandex.ru> <8760zakb7q.fsf@fencepost.gnu.org> <56892BDA.6060103@dancol.org> <871t9yk98g.fsf@fencepost.gnu.org> <568936F0.3060505@yandex.ru> <87wprqitj5.fsf@fencepost.gnu.org> <56893C8C.3060200@yandex.ru> <87oad2irtd.fsf@fencepost.gnu.org> <5689456A.1010601@yandex.ru> <87egdy8tyz.fsf@fencepost.gnu.org> <56895FDE.4060406@yandex.ru> <8760za8r4a.fsf@fencepost.gnu.org> <87h9iunkcg.fsf@web.de> <87h8hc4xw2.fsf_-_@web.de> <83tvlcsnee.fsf@gnu.org> <87pnw037ar.fsf@web.de> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1540318250 24907 195.159.176.226 (23 Oct 2018 18:10:50 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 23 Oct 2018 18:10:50 +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 Tue Oct 23 20:10:46 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 1gF18g-0006O4-4J for ged-emacs-devel@m.gmane.org; Tue, 23 Oct 2018 20:10:46 +0200 Original-Received: from localhost ([::1]:43684 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gF1Am-0004IE-D3 for ged-emacs-devel@m.gmane.org; Tue, 23 Oct 2018 14:12:56 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58901) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gF1Af-0004I7-Ef for emacs-devel@gnu.org; Tue, 23 Oct 2018 14:12:50 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gF1Ac-0002VP-9B for emacs-devel@gnu.org; Tue, 23 Oct 2018 14:12:49 -0400 Original-Received: from [195.159.176.226] (port=37294 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gF1Ac-0002UA-17 for emacs-devel@gnu.org; Tue, 23 Oct 2018 14:12:46 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1gF18S-00069C-Ek for emacs-devel@gnu.org; Tue, 23 Oct 2018 20:10:32 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 51 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:Rj2UvmIDvLQ8MVe2y6BrqZLD3vk= 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:230601 Archived-At: > I think so too, but it seems the majority of developers has a different > option, at least in this (old) thread. So I guess I'm gonna have to try and argue my case. OK, here are the advantages I see for `cl-case`: - simpler doc because its functionality is much more limited. - easier for people who already know Common-Lisp (or those who learned `case` from the cl.el package). - more concise syntax for branches that match multiple constants. Here are the problems I see with cl-case (regardless of pcase): - some users naturally write (case X ('a fooa) ...) without realizing that it also matches thew `quote` value. - tricky corner cases when trying to match the `t` or `nil` values (or `otherwise` as well, tho this one is much more rarely needed). - in (case X (a fooa)), the syntax looks a bit like a call to the function `a`: emacs-lisp-mode gets confused in terms of highlighting and completion, last I checked. - only works with numbers and symbols: can't use it to match against strings. In the specific case of using `pcase` where `cl-case` could also be used, the downsides I know of `pcase` are the following: - because it can also do a lot more, its doc is much more complex. - you have to use the more verbose ((or 'a 'b 'c) ...) syntax when matching several alternative values. - if you forget to quote your constant symbols the code behaves differently (and arguably surprisingly for some user) rather than giving you an error, tho in many cases the macro will detect a problem and give you a warning about a subsequent redundant branch (but the unsuspecting user will likely find it puzzling and it will take a while for him to figure out what's going on). The advantages are: - it fixes all four problems I described about `cl-case`. - it can accommodate many more cases, so it offers a smoother evolution. IOW, you will rarely find yourself having to stop using `pcase` and to rewrite the code to use `cond` instead just because you need to add a case that's a bit different from the others. - once you learn it, you can use it elsewhere, e.g. pcase-let, pcase-dolist, ... - Elisp+pcase is simpler than Elisp+clcase+pcase, so if we aim for overall simplicity we'd be better off without cl-case (to the extend that `cl-case` is too limited and hence we'll still want to use `pcase`). Stefan