From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuri Khan Newsgroups: gmane.emacs.devel Subject: Re: combining cond and let, to replace pcase. Date: Tue, 28 Nov 2023 01:49:10 +0700 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="8781"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Richard Stallman , Stefan Monnier , emacs-devel@gnu.org To: Manuel Giraud Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Nov 27 19:50:29 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 1r7ggf-00023x-5M for ged-emacs-devel@m.gmane-mx.org; Mon, 27 Nov 2023 19:50:29 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7gfg-0007Cs-Ml; Mon, 27 Nov 2023 13:49:28 -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 1r7gfe-0007Cb-MY for emacs-devel@gnu.org; Mon, 27 Nov 2023 13:49:26 -0500 Original-Received: from mail-oi1-x22d.google.com ([2607:f8b0:4864:20::22d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r7gfd-00009I-2a; Mon, 27 Nov 2023 13:49:26 -0500 Original-Received: by mail-oi1-x22d.google.com with SMTP id 5614622812f47-3b8382b8f5aso2910793b6e.0; Mon, 27 Nov 2023 10:49:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701110962; x=1701715762; darn=gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=/Vanl6/tfQzE/5DlYI5KZhERIMMRTPy0HxHKkjcyC4U=; b=gItszwm0VRp4hOgTYjB9jSuoN6Q4QD2At30ZHPnfjiP0eUAqQJ+lLBN7E38nytLle2 8spcYbtMdYr2AstRS+tNtedKv3gjDn3VQ0DFJhvzajbgY65sQovgbsrNEj4GUbAO6IWX x2LMa8snEEmHWbUw5O8YCVlbU+IoT5HG4MR2SxDbGy4AZ+7NCigdacRD58MoaEYU11tl RCzuQyddGqLEAJLLXe+Zlo9yMvGCWb56O0+ZAS5qG8OPD27mGQtCc/PMcHEe1qA4nLot SIIPJa3EiuuSFUxvWkz4+y36rpOfBJymIRUn3DIAXfK9vSA6xZo8/8CionULCgkgf/H2 qutA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701110962; x=1701715762; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/Vanl6/tfQzE/5DlYI5KZhERIMMRTPy0HxHKkjcyC4U=; b=GVXo+TVDJ648piqrbwzv/Wpnvy1R37fCzwascBwVoqxSgfEqI7PyGF0ronBp41l/XH vrQpPvGEogyKzAZZ4QJNvQ6RPfFg2jfzFGU2EQsiuNELe5C/NchMgiBi8L8rduwUa0IJ mLzNp1grWDGDJ6xCe9tQwBDLnRAgMmVEozC4yNLSHuEYccJPtFaSb7u51fw6v2kejOt4 4fbUfo9jWqIgA4/HtArtuYXtcWpUE4Odq+2t9uU1M/XM5s2XwUF+XFKKmPMlANcbhsdg npJHyhbvRaXRPpc0mFRAuags5iRUupzAD9f6QfuHdDxViltDHE6mUBP2ujQ4wJwfDSqX OZsQ== X-Gm-Message-State: AOJu0YyDPDyQ56k7vm8aAuBg+72vygVp57crGYNekk4Z2WwO14TF4U3U 6dI7LXy13iZF7RomqDK3z4EEFiJ+DiuMBVaU7oA= X-Google-Smtp-Source: AGHT+IH3ghJcVAOW6PfBJI6yUbWw4+CfNjVknoJuZuBJHD5D/rwHQz78eZFJ01FaWIE+uJnQmZqjZBI6FMbxoIxCN78= X-Received: by 2002:a05:6358:894:b0:16b:c414:ae2 with SMTP id m20-20020a056358089400b0016bc4140ae2mr13170670rwj.8.1701110962607; Mon, 27 Nov 2023 10:49:22 -0800 (PST) In-Reply-To: <871qcb83oa.fsf@ledu-giraud.fr> Received-SPF: pass client-ip=2607:f8b0:4864:20::22d; envelope-from=yurivkhan@gmail.com; helo=mail-oi1-x22d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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:313297 Archived-At: On Tue, 28 Nov 2023 at 01:14, Manuel Giraud via Emacs development discussions. wrote: > > Richard Stallman writes: > > [...] > > > > > ;; 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 str= ing? > > > > 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 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. The correct pattern matching behavior is to first check that the expression being matched is indeed a cons, and only if so, destructure it into its car and cdr. Similarly, attempting to match a two-element list (expt 2) with a three-element pattern (expt ,x ,y) is nonsensical and it=E2=80=99s not help= ful to bind y to (caddr '(expt 2)) =3D=3D nil. Same if the list and pattern have the same length but literal elements do not match, e.g. '(+ 42 73) against '(expt ,base ,exponent).