From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stephen Berman Newsgroups: gmane.emacs.devel Subject: Re: Replace trivial pcase occurrences in the Emacs sources Date: Thu, 25 Oct 2018 09:17:37 +0200 Message-ID: <87y3amfqb2.fsf@gmx.net> References: <20151216202605.GA3752@acm.fritz.box> <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> <83ftwvs7y9.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1540451791 31931 195.159.176.226 (25 Oct 2018 07:16:31 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 25 Oct 2018 07:16:31 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Oct 25 09:16:26 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 1gFZsX-0008Do-Ty for ged-emacs-devel@m.gmane.org; Thu, 25 Oct 2018 09:16:26 +0200 Original-Received: from localhost ([::1]:52889 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFZue-0000PV-Cw for ged-emacs-devel@m.gmane.org; Thu, 25 Oct 2018 03:18:36 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:37933) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFZtw-0007XF-7p for emacs-devel@gnu.org; Thu, 25 Oct 2018 03:17:55 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFZtt-0006NM-3t for emacs-devel@gnu.org; Thu, 25 Oct 2018 03:17:52 -0400 Original-Received: from mout.gmx.net ([212.227.17.21]:39401) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gFZts-0006Mn-R0 for emacs-devel@gnu.org; Thu, 25 Oct 2018 03:17:49 -0400 Original-Received: from rosalinde ([178.9.97.237]) by mail.gmx.com (mrgmx103 [212.227.17.168]) with ESMTPSA (Nemesis) id 0MVedf-1g5r1233R1-00Z1DT; Thu, 25 Oct 2018 09:17:39 +0200 Original-Received: from rosalinde ([178.9.97.237]) by mail.gmx.com (mrgmx103 [212.227.17.168]) with ESMTPSA (Nemesis) id 0MVedf-1g5r1233R1-00Z1DT; Thu, 25 Oct 2018 09:17:39 +0200 In-Reply-To: (Stefan Monnier's message of "Wed, 24 Oct 2018 16:52:23 -0400") X-Provags-ID: V03:K1:ipfDdUdL0NuE8Ubs4cf4IieJ7oro5Q6h1iuE1OcJdXSz222uBQn USoJbXB4g1arKJ7GUN8WfHnetuWeHh8OF1KnjrWSIGyJdAtJ3Ft3c0njm0Yxb3choUPknGh lcC+fLJj3hzfQX2aFAa6RQsoXOYD9hkOIoL1rJ1QVTWfXooSgjYCFwx/yCkBTEYp0f9gdL7 a+ibvstf4Sdsztc9aEAaA== X-UI-Out-Filterresults: notjunk:1;V01:K0:RC7wcIcMiag=:pj48tiPE64/Bm7pJrPqp8F 9+AzVJCtsrs3fTpJjxLenSuFKytD2R3vh9cKIizK3RTQPvg5SRSoKVtWtV1hdr3SHhw/FrDMh 4gnswNilGaCj1a0prHiQpQlZhm5zu1kmvED+w2FOhpLTTWuKPMT6F7VyWcnbt/J3uxb84kkL+ wz+P+OBybolinbE1aHspwZIimqdj99X88uvWKqlSZGXHp4XLhh7eYqiOMAiZJcT+VKzIh5nEU 5I66Yr8q6etAkZ8ftozf2WBakBJAWwd6U8FDvvRszpOjMeUh3MJur7nZPhQZYzZ1PsChfk+mD uj55NqJ9WXxDrxobRQswjkfji+9yUTmbP8Ujka5SQeI53v3Klq78J5bezhy/f7iSpXN0sFd4H Qeb5Lns3Ubu6QOOn2j/L+JLMOM6B0reXg29CTxP5cLschjdwRUq4VjBpT8yeeGxysviqJCYlc cwn8PZYeaqFetvc5P5nxzkfC+cPcnqw50VGK5FEPygXndROcacwhpHp4eXRQ/Ta4Nj4TpW1tv YbKx3C4bmT8377bBAY1zn+q9xENd28BY2N8Z/V+dKxUjKYfkclV6j9P9dGJKUbluHA4R72d3c CtAFrZIaCga1hdoxinGduepSQR+qP62w/vp3W/xS+Etow6K0f+H0Z7m0zhT8K1AltocgT3Lz5 8OSXTApjHmqZADdHWTTELGKyTW2TQRyS76uD26C+dlVnqM5cI9vRmLltSLMq9eOq6fjzW+ZBs j+Pr8H3BwB4KCKnt4QeIqLhqVtfB1F22g5VSNOcuKHeYb+GqIIER6QCgpdLweMmpIXCfH7Pi X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.17.21 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:230652 Archived-At: On Wed, 24 Oct 2018 16:52:23 -0400 Stefan Monnier wrote: >> (pcase this-param >> ('edit (todo-edit-item--text)) >> ('header (todo-edit-item--text 'include-header)) >> ('multiline (todo-edit-item--text 'multiline)) >> ('add/edit (todo-edit-item--text 'comment-edit)) >> ('delete (todo-edit-item--text 'comment-delete)) >> ('diary (todo-edit-item--diary-inclusion)) >> ('nonmarking (todo-edit-item--diary-inclusion 'nonmarking)) >> [...] > > Is the below any better? > > (cond > ((eq this-param 'edit) (todo-edit-item--text)) > ((eq this-param 'header) (todo-edit-item--text 'include-header)) > ((eq this-param 'multiline) (todo-edit-item--text 'multiline)) > ((eq this-paran 'add/edit) (todo-edit-item--text 'comment-edit)) > ((eq this-parom 'delete) (todo-edit-item--text 'comment-delete)) > ((eq this-param 'diary) (todo-edit-item--diary-inclusion)) > ((eq this-param 'nonmarking) (todo-edit-item--diary-inclusion 'nonmarking)) > [...] > > To me, it's more verbose and more complex because you need to double > check that the same var is tested each time before you can know that it's > equivalent to a C-style `switch`. > > IOW, I consider rewriting the `cond` to use `pcase` to be a form of > "common sub-expression elimination", or reduction of copy&paste. FWIW, this is basically the reason I used pcase instead of cond in the above code, it wasn't just to jump on the pcase bandwagon (and it didn't occur to me at the time to use cl-case). Steve Berman