From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Richard Stallman Newsgroups: gmane.emacs.devel Subject: Re: Instead of pcase Date: Mon, 11 Dec 2023 22:43:44 -0500 Message-ID: References: <87fs169mjj.fsf@posteo.net> <093f11a1-57c2-5e56-d39b-26fef1c67cbb@gutov.dev> <25942.25061.217864.329049@retriever.mtv.corp.google.com> <87zfzdcz6z.fsf@posteo.net> <87zfza2aq2.fsf@web.de> <7nmsv9zq6u.fsf@ecube.ecubist.org> <7nv89x5tsi.fsf@ecube.ecubist.org> <87o7focuf5.fsf@web.de> <875y1r10jr.fsf@web.de> <87v895iyzy.fsf@web.de> Reply-To: rms@gnu.org Content-Type: text/plain; charset=Utf-8 Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="8406"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Michael Heerdegen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Dec 12 04:44:35 2023 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rCthD-000226-0T for ged-emacs-devel@m.gmane-mx.org; Tue, 12 Dec 2023 04:44:35 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rCtgQ-0003TO-KY; Mon, 11 Dec 2023 22:43:46 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rCtgP-0003T9-7b for emacs-devel@gnu.org; Mon, 11 Dec 2023 22:43:45 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rCtgO-0003FO-Rc; Mon, 11 Dec 2023 22:43:44 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=Date:References:Subject:In-Reply-To:To:From: mime-version; bh=ynwOcXI4sIsV0bnV0OXThUBpgBlUHqenO8GyE8xtYco=; b=D6BRny2Rp9yk KHNG5pPikfgosidSd4uA7HdwJ7jiuckIq97yDgqeaWUs59qb4vnAvK3uJ9L9pMHZa3l1SP88SSwxv gNmWJi9fsNfZ4DcPWNx2D2VrcIOrZRFEu6TirRURXEng0Spj/L67DXQk86hnO6pcBLJeRJYkh7yMi M1gzRz6trl+1EPYyqYdSeDR/71Ku96aqFG6WfCTRsWFmy6ANzSIG2NzjFc9GMjQsHtbMBe3yUQM/r twQYyOEBtmO6C0kgAzEgX+fDcYxxTAsoY9Evx5NuLGnVljK/2qy5IHGHL9dt5juDiw9O1WuKwhwXn wtcHofnaNJjh8+iQaxtgOw==; Original-Received: from rms by fencepost.gnu.org with local (Exim 4.90_1) (envelope-from ) id 1rCtgO-0007ZL-JO; Mon, 11 Dec 2023 22:43:44 -0500 In-Reply-To: <87v895iyzy.fsf@web.de> (emacs-devel@gnu.org) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 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-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:313722 Archived-At: [[[ To any NSA and FBI agents reading my email: please consider ]]] [[[ whether defending the US Constitution against all enemies, ]]] [[[ foreign or domestic, requires you to follow Snowden's example. ]]] I think whoever wrote that code in byte-optimize-letX was fascinated by the challenge of writing as much as possible in pcase language and minimizing use of Lisp. Here's my version, which I think is a lot clearer. It illustrates some of the flexibility of cond*: * Use of ordinary Lisp fir conditions, * Matching against different objects. * Clauses that bind and then drop through. (defun byte-optimize-letX (form) (cond* ;; Bindings list is empty. (:match (`(,_ () . ,body) form) `(progn . ,body)) ;; Decompose the form (:match (`(,head ,bindings . ,body) form)) ;; Body is empty or just contains a constant. (:match ((or `() `(,(macroexp-const-p const))) body) ;; If the match succeeds, it always binds CONST. (if (eq head 'let) `(progn ,@(mapcar #'cadr bindings) ,const) `(,head ,(butlast bindings) ,(cadar (last bindings)) ,const))) ;; Body does nothing but return the last variable in bindings. ((let ((last-var (car-safe (car (last bindings))))) ;; Next line could be written using `match', ;; but the clarity of this is worth one cons. (and (symbolp last-var) (equal body (list last-var)))) (if (eq head 'let) `(progn ,@(mapcar #'cadr bindings)) `(,head ,(butlast bindings) ,(cadar (last bindings))))) (t form))) -- Dr Richard Stallman (https://stallman.org) Chief GNUisance of the GNU Project (https://gnu.org) Founder, Free Software Foundation (https://fsf.org) Internet Hall-of-Famer (https://internethalloffame.org)