From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Xiyue Deng Newsgroups: gmane.emacs.bugs Subject: bug#67669: 29.1; Drop text suggesting using `and' to replace `if' Date: Thu, 07 Dec 2023 09:49:13 -0800 Message-ID: <87fs0ducme.fsf@debian-hx90.lan> References: <87v89buhpl.fsf@debian-hx90.lan> <83sf4e34s8.fsf@gnu.org> <87r0jytm58.fsf@debian-hx90.lan> <83a5qm2u8v.fsf@gnu.org> 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="26897"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 67669@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Dec 07 18:50:31 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1rBIW6-0006hN-Ix for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 07 Dec 2023 18:50:30 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rBIVT-00020a-8j; Thu, 07 Dec 2023 12:49:51 -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 1rBIVR-00020E-Vh for bug-gnu-emacs@gnu.org; Thu, 07 Dec 2023 12:49:49 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rBIVR-0000DI-NZ for bug-gnu-emacs@gnu.org; Thu, 07 Dec 2023 12:49:49 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rBIVe-00027x-4n for bug-gnu-emacs@gnu.org; Thu, 07 Dec 2023 12:50:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Xiyue Deng Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 07 Dec 2023 17:50:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67669 X-GNU-PR-Package: emacs Original-Received: via spool by 67669-submit@debbugs.gnu.org id=B67669.17019713798125 (code B ref 67669); Thu, 07 Dec 2023 17:50:02 +0000 Original-Received: (at 67669) by debbugs.gnu.org; 7 Dec 2023 17:49:39 +0000 Original-Received: from localhost ([127.0.0.1]:43084 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rBIVG-00026x-KX for submit@debbugs.gnu.org; Thu, 07 Dec 2023 12:49:39 -0500 Original-Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]:47589) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rBIVC-00026g-3H for 67669@debbugs.gnu.org; Thu, 07 Dec 2023 12:49:37 -0500 Original-Received: by mail-pg1-x536.google.com with SMTP id 41be03b00d2f7-5c66418decaso829395a12.3 for <67669@debbugs.gnu.org>; Thu, 07 Dec 2023 09:49:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701971355; x=1702576155; darn=debbugs.gnu.org; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=e2YigYJMjmIVMW5B8J5oUqi5xGBj9wXgdDclBgOkEfQ=; b=gPgsBu3Z0Agec8jJL/VNN/ATIcWGc77mHINbPWU6v/lEp6O6QV5cPkH/6PQEQzD41L Huvf7uRlyHFmle1WkUKH5W6R4i3VSbiOWj7/qZ2DRD7XSAOSzCuWuz6fUfTGQqxPP3+3 6cnMYkHFUWwqFkKKyaFfeiE2WCgYBp/JQJvVJnRoyQ1J7okZhRkUeq+0Kge29DeSqctZ mDNktULJG+Dsx/Ik1kie90jnlwyQm9dYYpngXjC3HgX1ZqS0llRc24I2k/A2MQ9orBMV CdE1SPtjxHxkCYHkOWxa2EZCZY7bA/ugX7wP4mnIo/kZGOu+8/W32iSmGfQZFBoKy6PU rfyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701971355; x=1702576155; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=e2YigYJMjmIVMW5B8J5oUqi5xGBj9wXgdDclBgOkEfQ=; b=IQWNQKJg2Dca91A0Y57Lwfqiq7HbthSu/nld/6sRj9Hvv9sDKNsbqZUzC/NymkA81v /DsuWMjxeyv/qhKbJhFM/cun3/bWHNInEvD9GCFLiFbnW4MyvBVZprFXoNzwZ9w3iNeo LnAVLC5DrXU0WpUxxGq0221mmcpFE77JZgRwS8Go+IeaN5aW04sE+KCGh6taFHvzETv3 Sjf9wLm+jm/HOao8fjFSUUMXm2BLsrB+BFF8gbISikb69ecVL67RGTgZCygd6HJz43ss s8YXrYEr7BszL/9Vhp0EHFrVqp711l/UMWYQJ42LRkzJpyXzw6Gjq48MjquhtdnEiC9I LA0g== X-Gm-Message-State: AOJu0YzqLnPCrTgWBt7IFsvwBCEVFCe829UXjw9mQF510YlrWHchzULg SlMR/6CxZxqCE5k8Jd3wfCpFXRZx4RHBsw== X-Google-Smtp-Source: AGHT+IHmjGDscaRrP2RQaSfPwjBJ6VkkFqPGweiwFZORh1kPfSkdGQqqj2sFT+MydffVvtoKlNffZA== X-Received: by 2002:a17:902:ab57:b0:1cc:3a8a:f19b with SMTP id ij23-20020a170902ab5700b001cc3a8af19bmr2307760plb.14.1701971355319; Thu, 07 Dec 2023 09:49:15 -0800 (PST) Original-Received: from debian-hx90 (2603-8000-a400-0cdc-93f0-c81c-5fa0-c77c.res6.spectrum.com. [2603:8000:a400:cdc:93f0:c81c:5fa0:c77c]) by smtp.gmail.com with ESMTPSA id j4-20020a170902da8400b001d072591d77sm83407plx.247.2023.12.07.09.49.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 09:49:14 -0800 (PST) In-Reply-To: <83a5qm2u8v.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 07 Dec 2023 12:16:00 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:275693 Archived-At: Eli Zaretskii writes: >> From: Xiyue Deng >> Cc: 67669@debbugs.gnu.org >> Date: Thu, 07 Dec 2023 01:08:51 -0800 >>=20 >> Eli Zaretskii writes: >>=20 >> > AFAIU, the relevant fragment is: >> > >> > The expression looks like this: >> > >> > (if interprogram-cut-function >> > (funcall interprogram-cut-function string (not replace)))) >> > >> > If an =E2=80=98interprogram-cut-function=E2=80=99 exists, then Em= acs executes >> > =E2=80=98funcall=E2=80=99, which in turn calls its first argument as= a function and >> > passes the remaining arguments to it. (Incidentally, as far as I can >> > see, this =E2=80=98if=E2=80=99 expression could be replaced by an = =E2=80=98and=E2=80=99 expression >> > similar to the one in the first part of the function.) >> > >> > I don't see anything wrong here. Can you elaborate on why you think >> > the text in parentheses is inaccurate or incorrect or unclear? >>=20 >> Sorry I wasn't very clear. I was referring to the part "... could be >> replaced by an =E2=80=98and=E2=80=99 expression similar to _the one in t= he first part of >> the function_." But when I tried to search for `and' in the example >> code of that section I found no `and' usage at all, which confused me a >> bit. > > I think it means this part earlier in the node: > > (if (fboundp 'menu-bar-update-yank-menu) > (menu-bar-update-yank-menu string (and replace (car kill-ring= )))) To be super nitpicking, the text said "the one in the _first part_ of the function", while this code snippet you quoted is the second statement in the code example. If we look at the old code (which is currently marked as ignore in the texi source), the first part is: (and (fboundp 'menu-bar-update-yank-menu) (menu-bar-update-yank-menu string (and replace (car kill-ring)))) Which IMHO lets the text make more sense. But anyway. > >> It was not until I looked at the texi source that I noticed that >> the original example code did use `and' which I linked in my first >> email, and it was later replace by the current one from Emacs 22 which >> no longer used `and'. Thus I would consider the text in the parentheses >> you quoted to be obsolete. > > I don't think so. > >> And of course as I mentioned in the previous email, IMHO it is probably >> not a good advice to use `and' to emulate `if'. > > I disagree. I think the discussion of 'if' and 'and' there is > entirely appropriate and educational, and I personally do use these > interchangeably in some situations. Agreed on the point of being educational, and of course in the end coding style is mostly a matter of personal preference. However, I would argue a bit that in such case we wouldn't need `if' or `when' at all as both can be emulated by `and' and `or' if you are careful enough. On the other hand, `if' and `when' should exist for a reason. I quite like this suggestion[1] that `if' and `when' are used to guard side effects, whereas `and' and `or' are used for pure functions. Interestingly the current example you quoted changed from using `and' (as in the old version I quoted) to `if' probably based on this reasoning. Similarly I wouldn't suggest to replace `if' with `and' in the original example around the text we are discussing: (if interprogram-cut-function (funcall interprogram-cut-function string (not replace)))) as we are also guarding a side effect here. Wdyt? [1] https://emacs.stackexchange.com/a/14204 --=20 Xiyue Deng