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: combining cond and let, to replace pcase. Date: Sat, 25 Nov 2023 22:14:44 -0500 Message-ID: References: <87fs0w7smp.fsf@ledu-giraud.fr> 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="23279"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Manuel Giraud Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Nov 26 04:15:20 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 1r75c8-0005pE-1F for ged-emacs-devel@m.gmane-mx.org; Sun, 26 Nov 2023 04:15:20 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r75bd-00080Z-Me; Sat, 25 Nov 2023 22:14:49 -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 1r75ba-0007zu-3c for emacs-devel@gnu.org; Sat, 25 Nov 2023 22:14:46 -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 1r75bZ-0003H4-3h; Sat, 25 Nov 2023 22:14:45 -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=4Fi12gS5Jb8BzyC01i1vH6Q/zlftmx/jw6qtFyax45k=; b=LsOB1F9B/VNu m43UKlopZ4V2D8Vn4oaavCzmhjS9IDjsLYDzpGkIe6PwhNqnrmwCXVNq7OsY6DPhflzSyhLCLxk8O Qsl7P3Ps2G0Uzy94Ogecvf3Ibj32oaqkkinbvGRrd1K8n9b5o7/B1e3T22vUKvQ+NQgockqRy3Rou S9FF3OD+/a2nEsIA+zW895Hak8zPIOCe3gVOy+tSVSa9bzS/Moqw1AHiYRX2Pm6ZXUPGtajlIt8MS gFxO3J2ELxyuv7Q8iiU9DLKolWAaCU3t02fgY5iQWBGCtsypDt43yLZMqPqCR801mCRX3LhADrmQp skVsmJJe/iE0x66YCfjjOg==; Original-Received: from rms by fencepost.gnu.org with local (Exim 4.90_1) (envelope-from ) id 1r75bY-0002D6-RU; Sat, 25 Nov 2023 22:14:44 -0500 In-Reply-To: <87fs0w7smp.fsf@ledu-giraud.fr> (message from Manuel Giraud on Thu, 23 Nov 2023 09:58:54 +0100) 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:313230 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. ]]] > Only gut feelings here, but fall thru with bindings by default and > multiple t may surprise users and lead to not simple to debug code. It would be a trivial change to replace t with some keyword, for that functionality. Would it actually be better? What do other s think? Here's a more uniform version, in which each clause exits if it contains more than one element (after the possible keyword), and falls through otherwise. This makes it unnecessary to redefine what t means as a condition -- that can be written another way (see below). (cond* ;; Same as a clause in `cond', (CONDITION DO-THIS-IF-TRUE-THEN-EXIT...) ;; Execute FORM and ignore its value. (FORM) ;; Variables to bind, as in let (:bind ((x foobar) y z (foo 5) a)) ;; Bindings continue in effect. ;; Extracts substructure and binds variables around the rest ;; of the cond*. (:match (`(expt ,foo ,bar) x) DO-THIS-IF-IT-MATCHED-THEN-EXIT...) ;; Bindings continue in effect. ;; Like above but always falls thru to next clause. (:match (`(expt ,foo ,bar) x)) ;; Bindings continue in effect. ) To execute several expressions and not exit, use this: ((progn DO-THIS-UNCONDITIONALLY-AND-DONT-STOP...) -- 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)