From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: combining cond and let, to replace pcase. Date: Mon, 27 Nov 2023 18:12:11 -0500 Message-ID: References: <871qcb83oa.fsf@ledu-giraud.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21816"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Manuel Giraud , Richard Stallman , emacs-devel@gnu.org To: Yuri Khan Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Nov 28 00:13:17 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 1r7kmy-0005Vb-SM for ged-emacs-devel@m.gmane-mx.org; Tue, 28 Nov 2023 00:13:16 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7kmJ-0000ws-Pc; Mon, 27 Nov 2023 18:12:35 -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 1r7kmH-0000wM-KF for emacs-devel@gnu.org; Mon, 27 Nov 2023 18:12:33 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7kmD-0007Pp-B6; Mon, 27 Nov 2023 18:12:33 -0500 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id B6FCA442415; Mon, 27 Nov 2023 18:12:23 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1701126742; bh=OZw6rXhNyP4bte/rs4KMmZYP5cMEYV8/7sgT0Y0+MPM=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=JW70xoYqf5wERLTr0F/nF0LuhsjMgnu03VG8JGADAh99+/9FDAmkfuf4PAC92Olmc Mx+aSRXWMSNtmv/DZHhJ5Tz/8lcbpOZXKYt4EN0BkDxwxitl1Nm6ZDuIWApggKFMzT wTVF9VEsUsMVTHwQiyQ1Ju1PAX2eEgVOKns8O0mvgJDWQ+epNu6TtI5XEsajqSQDDp x2in0i2587SaKwxwljUtLV4AHx+GKVbAmk9vBOajoQa4Vmk6X+5+8nMcZtdFamV7ku uwjnY0qNyQyWQ396UimZhM3KNAY6vp4F/SgFS1k7Cqb37t7YDzY+ShoB5G5jH0d0gj 4p71jKo/MFuuw== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 1C79F442412; Mon, 27 Nov 2023 18:12:22 -0500 (EST) Original-Received: from lechazo (lechon.iro.umontreal.ca [132.204.27.242]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 074E712025D; Mon, 27 Nov 2023 18:12:22 -0500 (EST) In-Reply-To: (Yuri Khan's message of "Tue, 28 Nov 2023 01:49:10 +0700") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action 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:313301 Archived-At: >> > > > ;; Like above but always falls thru to next clause. >> > > > (:match (`(expt ,foo ,bar) x)) >> > > > ;; Bindings continue in effect. >> > >> > > What happens if `(car x)` is not equal to `expt` or if `x` is a st= ring? >> > >> > This form of clause should bind the variables unconditionally. If >> > matching provides a value to give a certain variable, the variable >> > should get that value. Otherwise it should be bound to nil. >> >> So these form of :match clause would bind variables even though it did >> not match? That seems counter-intuitive to me. > > Not only that, it=E2=80=99s just plain wrong. > > (pcase 42 > (`(,x . ,y) (format "%s:%s" x y)) > (_ "not a cons cell")) > =E2=86=92 not a cons cell But those above `:match` is not a test, it's a destructuring operation only, so it's more like (pcase-let ((`(,x . ,y) 42)) ...) > If I understand Richard correctly, 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` uses `car-safe` and `cdr-safe` tho it was not to avoid such errors (it was to allow those operations to be optimized away if the result is not used). `:match` could similarly use `car-safe` and `cdr-safe`. Stefan