From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: =?UTF-8?Q?Cl=c3=a9ment_Pit-Claudel?= Newsgroups: gmane.emacs.devel Subject: Re: Replace trivial pcase occurrences in the Emacs sources Date: Wed, 24 Oct 2018 15:00:46 -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> <83ftwvs7y9.fsf@gnu.org> <1249c6c5-6ff6-8b1e-102f-0b1b0942a42e@gmail.com> <83bm7js5ba.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1540407939 31176 195.159.176.226 (24 Oct 2018 19:05:39 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 24 Oct 2018 19:05:39 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Oct 24 21:05:35 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 1gFOTH-0007y7-2h for ged-emacs-devel@m.gmane.org; Wed, 24 Oct 2018 21:05:35 +0200 Original-Received: from localhost ([::1]:49904 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFOVN-0006HU-HH for ged-emacs-devel@m.gmane.org; Wed, 24 Oct 2018 15:07:45 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60947) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFOV4-0005wZ-Ty for emacs-devel@gnu.org; Wed, 24 Oct 2018 15:07:31 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFOOp-0005lQ-6R for emacs-devel@gnu.org; Wed, 24 Oct 2018 15:01:04 -0400 Original-Received: from mail-qk1-x733.google.com ([2607:f8b0:4864:20::733]:43107) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gFOOk-0005S2-M3; Wed, 24 Oct 2018 15:00:55 -0400 Original-Received: by mail-qk1-x733.google.com with SMTP id m17-v6so4080072qkk.10; Wed, 24 Oct 2018 12:00:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=mXwvD8v4iwDliDL+LN5LQVPYxUvoWtf0nAY0OqjlvJw=; b=Mjy7s4Oz0UIS7HcVxo6DguKl2X+NGdsX3rR+Qv3mk0tw3MruB3BbwuzOIaa7DiMQAa 3lCOdhKNNgdMIpnxqa8vinhuw0FoVsocTC5gmvN74Nx/6Fx/lIojit2myV+nUgqsbcen 5D86G/l+Mtzcra+TlDTikkO3kSdXtAehoEJla0rAtKlY1TXHcrF4T5Gnk9yZy9rMndN2 AyHNYl4YMR8XIp+WslvUCzuh05hs859BFTFO/W5chO9t3A7VTyGLVRAk4r/lwadgP7i4 vOobR2uxwS6UPHeHqkpyzv3JFC1Igetaa34a96ZM4pVg40qbH9VPKphDv58pqpI7fxBW QS8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=mXwvD8v4iwDliDL+LN5LQVPYxUvoWtf0nAY0OqjlvJw=; b=EuqYL2uklYXJk84s27UdHZk9k0H0ENOKBKjgefcH8R5ieloSAQgdpNRCaTddnBCtn6 I7yP1wTfbHvqbeEf5QhoTEFrBvj0CmPdt8cg/3xa/Y2ELGAYFaV0V5pPzG9b42ijLeLx yjfCogySAjK5cdCONSgG4XZSJEHaJPpgqwjl2g+aJTjGY9ZQ1VRXvBbt3Dweslgh1upP Dz5T4+aG993Izp0tn5nErcak2fPfrHo2px1ndvpegBjkMfcFxt0xm/TDhzP9tnjnBgva zrLv8uhL+9eygPEqYSm8h9iTnbj9rohMKnQ8gYPYQEcr1+RGfdoj49RtyJ+uBSZzOvd4 x3Og== X-Gm-Message-State: AGRZ1gJmY4ZKw5iCGH8JetybsqpGgg6Iu2O39z4u7pHHrWZkejsqIdHM MOseD5K0uiNXQtS1VryvpSsjpgwR X-Google-Smtp-Source: AJdET5dAxkqHOmPKSK5Cm2AzAWJEKPfgGco8RqVwmJHg6z1Zb8YjnH1C4pCweb2mA7ySfFM+Onc19w== X-Received: by 2002:a37:8c42:: with SMTP id o63-v6mr3428903qkd.187.1540407648107; Wed, 24 Oct 2018 12:00:48 -0700 (PDT) Original-Received: from [18.26.2.123] (26-2-123.dynamic.csail.mit.edu. [18.26.2.123]) by smtp.gmail.com with ESMTPSA id k19-v6sm46940qkk.82.2018.10.24.12.00.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Oct 2018 12:00:47 -0700 (PDT) In-Reply-To: <83bm7js5ba.fsf@gnu.org> Content-Language: en-GB X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::733 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:230643 Archived-At: On 24/10/2018 12.00, Eli Zaretskii wrote: >> From: Clément Pit-Claudel >> The repetition of "eq" in each "cond" branch just looks redundant to me > > If that's what bugs you, then how about > > (setq foo (assoc bar '((1 . one) (2 . two) ...))) This only works for constant branch bodies, and I find it marginally harder to read (especially if a default value is specified). But I agree that it's not a bad solution when the branch body is constant. For large collections, I imagine you would use a hashtable? Is that how the switch bytecode is implemented? IIUC, cond and pcase will be translated to a switch, but not assoc, even with a constant association list. >> and I have no trouble reading the pcase forms. > > Please don't forget those who will read your code. A code is written > once, but read many times. It should be readable and > self-explanatory. Of course. Note that I mentioned reading the pcase forms, not writing them. I'm just pointing out that there are readers who find pcase more readable than either assoc or cond with eq tests.