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 00:59:48 +0700 Message-ID: References: <87v89t7y13.fsf@neko.mail-host-address-is-not-set> <87zfyz15w1.fsf@neko.mail-host-address-is-not-set> 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="20865"; mail-complaints-to="usenet@ciao.gmane.io" Cc: rms@gnu.org, emacs-devel@gnu.org To: Tomas Hlavaty Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Nov 27 19:00:40 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 1r7fuR-0005FZ-NI for ged-emacs-devel@m.gmane-mx.org; Mon, 27 Nov 2023 19:00:39 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7ftt-0004dw-Vb; Mon, 27 Nov 2023 13:00:05 -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 1r7fts-0004di-Bj for emacs-devel@gnu.org; Mon, 27 Nov 2023 13:00:04 -0500 Original-Received: from mail-oi1-x229.google.com ([2607:f8b0:4864:20::229]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r7ftp-00060P-JT; Mon, 27 Nov 2023 13:00:04 -0500 Original-Received: by mail-oi1-x229.google.com with SMTP id 5614622812f47-3b842c1511fso2834810b6e.1; Mon, 27 Nov 2023 10:00:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701107999; x=1701712799; 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=r82n5tk36Bj2pD4hg+pEEDIlUSB/NMDSRXLHj/MFqEQ=; b=S+n64bHh0XyaUwPsDWXPC4F/VqBQyG59D5LA/XNhhnHbRManid3JUIDKKCK8ZOZsif PgX5SYPupqbdIN+/t2qpcYmJft7aGGTgezHIQLSR/2KHHJEkNzXtZvbYKkkMbyPPvU2h ZAfwg6W19lgTugT3JlhYbUqfQQlImvOAI2hHcUT8E14JCTyf78k3nlFqUO+tpbXoIJVo TyoXU/CF7iZ066cdSslYOckSlk5QwQ+6VPcPJvnGy+u4KjUwfRZBZ2+Y93ZuhW1gzf7h Bh9D+lZqriX7G3JHSPGkp6Ov59CvtB341VfDQgxyutgm4mFt3wqMCgzmq5TOz7cMhM6J mI6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701107999; x=1701712799; 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=r82n5tk36Bj2pD4hg+pEEDIlUSB/NMDSRXLHj/MFqEQ=; b=uhH7DIB00fID6VosyA/SixLLjKqmS1zJWycfMoTAAeRAIlKkHaJmtg+HAaPSpwND9D 5WXPfbKjuwU55A362QFokfYP0n2qo/Aid8aR67PWkG2OYKeDbr5HuihNqSYkAQ8/yMw6 OcVjGRwvD28hw4D9shWPXqMpSp0G1bPbNcsFRMN49+sPkZCSWme5I2dbx9RnbOEvjy4z grWYD3kZT2F71bAyN/2PlFden+dFnTD0Fm7etclP/3HWh9mTP/OZx5BCu2nTGmtfDlGU BI9moh0tnI+k3WT7zsuvRw8rVuDoIS7CiT2loBZP6Brp8wDnYAaouoRaXfSbshZDOZFt lkGA== X-Gm-Message-State: AOJu0Yyd53GfJT02MGr6kFhuBs5Q4ZWpu7f3YB0LF2oyVvPr3MxEb8XU yaJ/clTcfE7rH/zrLpgGYl/gTH7j0gfn7uMUfbKpQVCF X-Google-Smtp-Source: AGHT+IEvDtruSyAGb652XOOF8Dnti3tsBnGZy/IJ1mPqXsRNnsy/dpktyYeuv6VBiyBKmhRR8hf4iJNslL81NMafjxY= X-Received: by 2002:a05:6358:4194:b0:16b:fbd6:9bab with SMTP id w20-20020a056358419400b0016bfbd69babmr13027650rwc.32.1701107999466; Mon, 27 Nov 2023 09:59:59 -0800 (PST) In-Reply-To: <87zfyz15w1.fsf@neko.mail-host-address-is-not-set> Received-SPF: pass client-ip=2607:f8b0:4864:20::229; envelope-from=yurivkhan@gmail.com; helo=mail-oi1-x229.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:313293 Archived-At: On Tue, 28 Nov 2023 at 00:10, Tomas Hlavaty wrote: > even better:> > (or > ;; Same as a clause in `cond', > (when CONDITION > do-this-if-CONDITION-then-exit...) > ;; Variables to bind, as in let > (let ((x foobar) y z (foo 5) a) > ;; Bindings continue in effect. > ...) > ...) This reminds me of the times before Python 2.x had a ternary operator =E2=80=98X if CONDITION else Y=E2=80=99. Some FAQs said =E2=80=9Cyou can us= e this trick: =E2=80=98CONDITION and X or Y=E2=80=99=E2=80=9D, with a small print (someti= mes skipped) =E2=80=9Cas long as you guarantee that X evaluates to a truthy value=E2=80=9D. This is very error-prone. Novices can and will get bitten by this. * =E2=80=98or=E2=80=99 evaluates its arguments in turn until one of them ev= aluates to non-nil. * =E2=80=98when=E2=80=99 and =E2=80=98let=E2=80=99 evaluate to the last bod= y form if any, or nil if none. So, for the intended effect of exiting the =E2=80=98or=E2=80=99 when a bran= ch is taken, one has to make sure to terminate that branch with a truthy expression: (or (when CONDITION do-this-possibly-returning-nil :break) (let (BINDINGS) do-something-else-possibly-returning-nil :break) =E2=80=A6more branches=E2=80=A6) Also, a =E2=80=98cond=E2=80=99 or a =E2=80=98pcase=E2=80=99 form will retur= n the result of the branch taken, which can be nil. An =E2=80=98or=E2=80=99 form will return the resul= t of the branch taken, as long as it is not nil. A branch that returns nil will result in evaluation of the next branch.