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: combining cond and let, to replace pcase. Date: Fri, 17 Nov 2023 22:03:56 -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="39763"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Spencer Baugh Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Nov 18 04:04:42 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 1r4BdS-000A6Z-0C for ged-emacs-devel@m.gmane-mx.org; Sat, 18 Nov 2023 04:04:42 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r4Bcl-0006lH-B9; Fri, 17 Nov 2023 22:03: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 1r4Bck-0006km-4a for emacs-devel@gnu.org; Fri, 17 Nov 2023 22:03:58 -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 1r4Bcj-0005Tx-BL; Fri, 17 Nov 2023 22:03: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=CbBXaB6IIZt4lvQ+Y4BC8+0E/OjBYNC5zQQ7750FlRM=; b=KUfutK1m6ahV q9tOHFkPGoRQ/cwnPl/3NRV2JU9SMsVChfQknt2cRil9bo62/R7jbbBp+ZGJQEtfQJbADRA16xV2t mjc+92qPVb/QJqQ4EmZJB5gx7WpndCVExOYOYkxbfRHY6F9hj4PxXEWnpJhwMt78ikhMRYRkvtHSb gVSRS398FlWNr/MXiztbxfpTe4YyFhNVK/F+p41N9fyTGdEet97QlSZXulKC9ww1twRKQoLlzADQh e21Mq1hGlDCdivGIiKtzcEwALXQ2a1vhzUp1WvyROXdMM3YcOtGPEi6COMcN1SpqVZH2n2GqmQztX h/868crmZjBzc+GUV8t6tQ==; Original-Received: from rms by fencepost.gnu.org with local (Exim 4.90_1) (envelope-from ) id 1r4Bci-00043P-VJ; Fri, 17 Nov 2023 22:03:56 -0500 In-Reply-To: (message from Spencer Baugh on Thu, 16 Nov 2023 10:20:49 -0500) 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:312883 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've thought before that it would be nice to have a cond-let construct, > like if-let and when-let. Here's an example to show what I have come up with along these lines: (cond* (:bind (x foobar) y z (foo 5) a) ;; variables to bind, as in let ;; I'm also thinking of using nil instead of :bind. ;; t as condition means run this clause unconditionally ;; then continue with next clause. (t do-this-unconditionally-and-dont-stop...) ;; Tests with a new function `match' which I'm going to work on next. ((match x 'foo) ...) ;; t in the last clause means the same as in previous clauses, ;; but you can think of it as being the same as in `cond'. (t do-this-as-last-resort) ) Rhe idea is that conf* does part of pcase's added functionality, and `match' will do the rest. But it is not necessary to cram _all_ the additional matching functionality (to compare to pcase) into a single new function. We could have more than one new function, eacn for its own kind of pattern matching. Some of them could do destructuring as well as matching. I hoipe that using a few constructs to divide up the job will avoid the kludginess of pcase's bells-and-whistles-for-everything approach, resulting in something equally convenient but made of simple components. -- 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)