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: Tue, 28 Nov 2023 22:41:41 -0500 Message-ID: References: <871qcb83oa.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="30835"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Yuri Khan Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Nov 29 04:42:11 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 1r8BSl-0007ou-EN for ged-emacs-devel@m.gmane-mx.org; Wed, 29 Nov 2023 04:42:11 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8BSN-0001OQ-UE; Tue, 28 Nov 2023 22:41:48 -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 1r8BSI-0001NA-BE for emacs-devel@gnu.org; Tue, 28 Nov 2023 22:41:42 -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 1r8BSI-0007x1-2X; Tue, 28 Nov 2023 22:41:42 -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=kDTYDsw/yD1Fa4nFi39Wea5BaVnAS2Dk5XoCLpfbSCo=; b=ekDZe+npIGa3 2YLklkqXbuuQ27VsOEQN3G1rFqS265raa844jnJJRRjINOhZDhDhbLNYAdyCGAwRUxGOJxorRQBSK s+lN5m0h4DaVMufjzz+hGgIYz0Uz/LfryUF5oFClDKTiY8fCNZcQY3+NRpar6eej4pb/fbcRXVgnQ ipCSglc/ey5TWf+DiZE0pNqSsgHHPc0bNTvLZhmu8tFIVqADo9XOeX2iBQtPY+qxxgq6pzjhIIssj 6qV2DaAKca442Dzavq/BHk9LTC6sm3wpTMI1Q8Te8rAJG+lDBKApnjlIb3Ze92GRoNH645OZKw+k7 zPLvdlnysvZOC8S17pLQ6Q==; Original-Received: from rms by fencepost.gnu.org with local (Exim 4.90_1) (envelope-from ) id 1r8BSH-0001F3-R3; Tue, 28 Nov 2023 22:41:41 -0500 In-Reply-To: (message from Yuri Khan on Tue, 28 Nov 2023 01:49:10 +0700) 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:313350 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. ]]] > (pcase 42 > (`(,x . ,y) (format "%s:%s" x y)) > (_ "not a cons cell")) > → not a cons cell > If I understand Richard correctly, Alas I think we are miscommunicating. the corresponding :match will > unconditionally attempt to bind x to (car 42) and y to (cdr 42), which > results in a run-time error. pcase has one kind of matching clause. cond* has two kinds. It is possible that this distinction is not clear enough in the text I posted. In this version, each clause exits if it contains more than one element (after the possible keyword), and falls through unconditionally if it has only one element (after the possible keyword). For the second kind, I think this addresses your concern. (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 no longer in effect. ;; Like above but always falls thru to next clause. (:match (`(expt ,foo ,bar) x)) ;; Bindings continue in effect. ;; All the variables mentioned in the pattern ;; are bound whether match succeeds or not. ;; If a value can be determined from an incomplete match, ;; the variable gets that value. ) -- 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)