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: Fri, 15 Dec 2023 23:23:55 -0500 Message-ID: References: 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="4526"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Adam Porter Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Dec 16 05:24:51 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 1rEMEM-0000za-Vg for ged-emacs-devel@m.gmane-mx.org; Sat, 16 Dec 2023 05:24:51 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rEMDX-0001Vp-Aq; Fri, 15 Dec 2023 23:23:59 -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 1rEMDV-0001Sb-JE for emacs-devel@gnu.org; Fri, 15 Dec 2023 23:23:57 -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 1rEMDV-0001HO-4h; Fri, 15 Dec 2023 23:23:57 -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=dXxA2K37z3Mo+1PGeMZNrNTn2sUK2DOuCsZkz0swvmI=; b=mc/kfOyx1Ax2 NfNgw58V7urwSUxxvCMYITw1V37iZOaLIJUXAEYNHzIgMaIl3nDA9G6KDMj2W0dc6oI+0cH5klQQx H0pvdUuHbDEEJ9lu0FQvOchrtEXHHZ2IbKvODhB1yn6U7RVMKdqsOTRUg6qszRstd/bkuGTOu2i/Z 0/JjkZEGhUdd2dkuettMraZ7cxP6U8vz//ABUgw+ItUx7MeaBNaMng4hdg496R1MXO8RWJkg791U0 XXyJrTt+hgdCIw8tLEg+5W5kD9aHLyDG9kCSGc+SG5gBgLL4X++PBX+F6jOhfqSmq1HF1/QceokuO QkW7ump136ZBF/tpRqWQpA==; Original-Received: from rms by fencepost.gnu.org with local (Exim 4.90_1) (envelope-from ) id 1rEMDT-00035f-Pw; Fri, 15 Dec 2023 23:23:56 -0500 In-Reply-To: (message from Adam Porter on Tue, 12 Dec 2023 19:32:09 -0600) 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:313865 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. ]]] > > (defun byte-optimize-letX (form) > > (cond* > > ;; Bindings list is empty. > > (:match (`(,_ () . ,body) form) > > `(progn . ,body)) > This is nearly identical to the equivalent pcase syntax, only adding > `:match'. Since pcase's (and I suppose cond*'s) purpose is pattern > matching, this seems redundant and unnecessarily verbose. That's right. pcase has only one kind of clause, and all clauses match against one single value. cond* is more powerful and therefore it requires keywords to specify non-cond clauses. > > ;; Decompose the form > > (:match (`(,head ,bindings . ,body) form)) > I suppose it is largely a matter of taste, but I strongly dislike > fall-through clauses. While it seems convenient here, as it allows the > removal of either a redundancy (reiterating bindings in multiple > clauses) or a level of nesting, its bindings are also implicit rather > than explicit, as the scope of the binding form is not enclosed by > visible boundaries (i.e. parens). These bindings run from the place they are made to the closeparen at the end of the containing cond*. I think those bounds are easy to see. The use of a fall-through :match clause avoids the need to bind the variables separately for each clause, and the chance that they may differ (not incorrectly, but perhaps confusingly) in different clauses. However, it shares with pcase the design idea that variables to be bound by pattern matching are buried inside of a pattern, not centralized in one list that makes them easy to find. If people generally find that confusing, perhaps it would be good to change the fall-through :match clause so that the variables to be bound _must_ be listed "redundantly" in a previous :bind clause. This would make the code a little longer but make it easier to read. > > ;; Body is empty or just contains a constant. > > (:match ((or `() `(,(macroexp-const-p const))) body) > This seems even more confusing to me. The equivalent pcase form is: > `(,head ,bindings . ,(or '() `(,(and const (pred macroexp-const-p))))) I think the cond* method is simpler. (macroexp-const-p const) is both simpler and more natural than (and const (pred macroexp-const-p)). -- 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)