From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: JD Smith Newsgroups: gmane.emacs.devel Subject: Re: Code for cond* Date: Tue, 23 Jan 2024 23:49:06 -0500 Message-ID: <1AD5807F-91F7-4B92-BCB0-D0FEA904A75D@gmail.com> References: Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.300.61.1.2\)) 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="622"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Jan 24 05:50:18 2024 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 1rSVDO-000AXB-J0 for ged-emacs-devel@m.gmane-mx.org; Wed, 24 Jan 2024 05:50:18 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rSVCX-0004sd-Ae; Tue, 23 Jan 2024 23:49:25 -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 1rSVCV-0004sG-CR for emacs-devel@gnu.org; Tue, 23 Jan 2024 23:49:23 -0500 Original-Received: from mail-qv1-xf36.google.com ([2607:f8b0:4864:20::f36]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rSVCR-0008Io-Uy for emacs-devel@gnu.org; Tue, 23 Jan 2024 23:49:22 -0500 Original-Received: by mail-qv1-xf36.google.com with SMTP id 6a1803df08f44-681922a61baso41370476d6.1 for ; Tue, 23 Jan 2024 20:49:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706071758; x=1706676558; darn=gnu.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=KtbCv8WcEvn3DoRxVSGNyCRl6Hbvx2UmPdhUbYnZFgA=; b=R5FVtnl3ERvouqUWTnwJXkL18Zq1DWYfkDzT2uL7RrFxyyKf5+Cij/56TtyFV55iI1 6IeMbimIK2q1zx4m2SjURPNdmudzJnRHUN/8GPSJnnhFdWO/FZNYuj7szw2biaqywbFa fDtWsYdVk4OdH+ETh8NOF9tVxmMTnkea1YX7eWP1jZf5Pm3JZ6irO6p19vIvy619haDW bQQsl6T6c3yv/BaG7LI8Kg3AmkOftxbgqOYSTduOTrDYWuX0UYzEWstItHK7bzt5M1sn AAMAOp8PBzSi8E6OgFUN2K8OOi1T8obvhRCU8kZkdxB0gDplLT3EWjFP5kO7EtWYXQHY 8b6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706071758; x=1706676558; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KtbCv8WcEvn3DoRxVSGNyCRl6Hbvx2UmPdhUbYnZFgA=; b=MlVRVKeDJ95qGsBSOUjqPRqHM4GV0cNwa9i1KrJErRnQt7viB2x8VWYaKIY1BQSdZf RSJL3+oPi6baN7ilhYg6s5BFX8SK6rwG9rqoRSEKKdT1rcM9rI4fHRr4FBoC9SGQMx1H O9YlJSeojn0s4zGEuYXyXO3QafSHuwYBEIWYXjC/pX/rZcB7pdGte4bWxEPnoF8F0Hee kJFukkVGsTSOoQ+WbERmc9FvLup6IZXxXzc63bYqvuKrGcxs4GgHkzb0woRS6dJtiIj9 Q3YC3izGM5GZqLrEdCFq0gTmAhllkc6kLgyvO8VeoPEadP1KxaJz6oizqE+MnsOdFv+i 7Xhg== X-Gm-Message-State: AOJu0YyPBwfyyYyUnV7ldB/VcTMO0ShYReBNRGPioDYIi60llXs9Goya zN+vyndeXuM9/rYeb6Q9Miv2jX6LB4aMLnGbqTmUlGuzyObxfFkV X-Google-Smtp-Source: AGHT+IFswjf0ap62WtOYD4j1m5Z4R+mLVCU0oXM858FAHNsQLCx1yG70SU4BYCfMG3ygYCNlCQwJxw== X-Received: by 2002:a05:6214:2622:b0:686:abae:b8a1 with SMTP id gv2-20020a056214262200b00686abaeb8a1mr1018987qvb.57.1706071757968; Tue, 23 Jan 2024 20:49:17 -0800 (PST) Original-Received: from smtpclient.apple (cm-24-53-187-34.buckeyecom.net. [24.53.187.34]) by smtp.gmail.com with ESMTPSA id es2-20020a056214192200b0067f339c0c16sm4136492qvb.134.2024.01.23.20.49.16 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Jan 2024 20:49:17 -0800 (PST) In-Reply-To: X-Mailer: Apple Mail (2.3774.300.61.1.2) Received-SPF: pass client-ip=2607:f8b0:4864:20::f36; envelope-from=jdtsmith@gmail.com; helo=mail-qv1-xf36.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:315282 Archived-At: In general I=E2=80=99ve always felt cond by itself was missing some = functionality and could really use the ability to make bindings =E2=80=94 = a cond-let if you will. Even making and testing bindings local to each = cond clause would be a real advance[1]. Pattern matching adds another = level of complexity I hadn=E2=80=99t considered, but overall I'm = supportive of efforts to improve cond. I=E2=80=99ve used pcase lightly, but to be honest have always winced = when I have encountered it in code I really need to understand. As = others have already discussed, the similar looking but in fact = semantically distinct domain language has always thrown me (unlike = cl-loop, whose language is not easily mistaken for regular elisp = syntax). But oddly enough, this thread discussing its potential replacement has = given me the key insight =E2=80=94 =E2=80=9Cimagine running list = interpolation backwards=E2=80=9D. With that mental model, I find I can = now read pcase forms much more easily and confidently. A short = introductory paragraph in the elisp pcase documentation which explains = this approach to its novel syntax would have gone a long way for me. > On Jan 23, 2024, at 1:10=E2=80=AFPM, Stefan Monnier via Emacs = development discussions. wrote: >=20 >> ((match* `(expt ,foo ,bar) x)) >> ;; Bindings continue in effect. >=20 > Same comment as before: I like having both "bindings for the clause" > and "bindings for the rest", but having the two be syntactically > identical will lead to confusion. This is a significant concern. If I=E2=80=99m understanding the design = correctly: (let ((var outer-value)) (cond* ((bind* (var (some-complicated-function-that-returns-nil)))) ((bind* (other-var (some-other-function)))) <... lots of other clauses> (t var))) would return a different final fall-back value than the nearly identical = form: (let ((var outer-value)) (cond* ((bind* (var (some-complicated-function-that-returns-nil))) t) ; <-- = hidden danger ((bind* (other-var (some-other-function)))) <... lots of other clauses> (t var))) with a single `t=E2=80=99 added, perhaps a page above, deep inside a = sibling clause. That kind of =E2=80=9Cspooky action at a distance=E2=80=9D= would in my view lead to hard to track down errors and difficult to = parse code.=20 Perhaps let* could be used for binding variables within clauses, and = bind* for bindings which remain in effect for the rest of the construct, = ignoring any final value given in the ((bind* )) clause. But even with = that disambiguation, I=E2=80=99m so used to =E2=80=9Clooking upwards to = a parent let-form for the active bindings=E2=80=9D that establishing = bindings in a sibling clause like this would take some getting used to. [1] I regularly convince myself that it=E2=80=99s such low hanging = fruit, there must in fact already BE a cond-let, and I go hunting for = it. The obvious interface seems like such a straightforward extension = of if/when-let, that there would be absolutely nothing new to learn: (cond-let (((var value) (dvar (derived-from var)) ((has-the-right-stuff-p dvar))) (cons 'correct dvar)) (((foo value2) (bar (1- foo)) ((< bar 0))) (cons 'incorrect bar)) (t nil))