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: cond* Date: Wed, 20 Dec 2023 23:20:36 -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="9610"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: =?iso-8859-1?Q?Jo=C3=A3o_T=C3=A1vora?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Dec 21 05:21:08 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 1rGAYW-0002JB-FZ for ged-emacs-devel@m.gmane-mx.org; Thu, 21 Dec 2023 05:21:08 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rGAY2-00041Z-SD; Wed, 20 Dec 2023 23:20:38 -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 1rGAY1-00041Q-OP for emacs-devel@gnu.org; Wed, 20 Dec 2023 23:20:37 -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 1rGAY1-00058S-GN; Wed, 20 Dec 2023 23:20:37 -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=75zLwCr0LRJKxJXI3gxkKMzQErhPq5/O/Lqg5o3MszQ=; b=p+SUxQDkQkr9 wsQU9Z8839r8iXbi17kEl/6N4yFb4BOetTkr/0z586Ahr2wIbZNTsHsJLPoRRJbziFoBeNCExGjMC XM8NSVYJXL45y8ci2bCVohh7V77d1SZ+uLn8nfYIW42WCBxl0eJ7+Jk+ehD9SuhZRU1QIevA+tUDp ChBvdMeiKB6AbR4Kcmf7I0SKegRFQ5FiwfTsktORSPSNdVniA3SuvhYSGtd1ZiPIPqwNCWWdGPwVw SoNtk2vGDXFbAiuaXZJ8OZF0OMU1fbnVF0rHkhpq+Ncsn8QQokolIPzqb+2i2AmCah7b0Sg5iqBhm xNVgYdgQ/W/cyqNMYyUy+A==; Original-Received: from rms by fencepost.gnu.org with local (Exim 4.90_1) (envelope-from ) id 1rGAY0-0006t7-Vf; Wed, 20 Dec 2023 23:20:37 -0500 In-Reply-To: (message from =?iso-8859-1?Q?Jo=C3=A3o_T=C3=A1vora?= on Mon, 18 Dec 2023 10:08:33 +0000) 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:314026 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. ]]] > am I going to use BAR and FOO Are you talking about this? (cond* ((match* `(expt ,foo ,bar) x)) (t (something-that-depends-on FOO BAR) ; is this how to use it? ) in a form that is not contained > in any form that declares BAR and FOO as they are matched > and bound? "Declares BAR and FOO as they are matched and bound" is somewhat stramge usage of those words. It is not entirely clear what that means. And I am not sure what code you are talking about. What you quoted is not an example of code. It presents various sorts of clauses that a cond* can contain, but not meant as one cond* expression. Those clauses do not try to work together validly. So you're judging them by a criterion they do not try to fit. This tries to be a real example: (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))) head, bindings and body are bound in the cond* form, as specified by the fall-through second clause, and they can be used in the rest of the cond* clause. -- 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)