GNU bug report logs - #67669
29.1; Drop text suggesting using `and' to replace `if'

Previous Next

Package: emacs;

Reported by: Xiyue Deng <manphiz <at> gmail.com>

Date: Wed, 6 Dec 2023 21:48:01 UTC

Severity: normal

Found in version 29.1

Done: Xiyue Deng <manphiz <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


Message #26 received at 67669 <at> debbugs.gnu.org (full text, mbox):

From: Drew Adams <drew.adams <at> oracle.com>
To: Xiyue Deng <manphiz <at> gmail.com>, Eli Zaretskii <eliz <at> gnu.org>
Cc: "67669 <at> debbugs.gnu.org" <67669 <at> debbugs.gnu.org>
Subject: RE: [External] : bug#67669: 29.1; Drop text suggesting using `and' to
 replace `if'
Date: Thu, 7 Dec 2023 19:37:30 +0000
> I quite like this suggestion[1] that `if' and `when' are used to guard side
> effects,

More clearly, `when' and `unless' (not `if', which is general - no special suggestion) are used to suggest (to humans) that they're used _only_ to perform side effects.  With this convention, code shouldn't depend on their (always `nil') return value.

> whereas `and' and `or' are used for pure functions.

That too isn't really the convention (though it is what's said in that emacs.SE answer).

What should be said is that you use `and' and `or' when _the return value matters_, i.e., when it's used somewhere.

That does _not_ preclude the use of `and' and `or' to perform side effects.  It's simply that the _return value matters_.  Unlike `progn', the (Boolean) return value of each of their "steps" (sexps) determines whether subsequent ones are evaluated.

I've added another answer to the emacs.SE question you cited:

https://emacs.stackexchange.com/a/79744/105

But as you correctly noted, such conventions are a question of personal (or group) coding style.  Lisp doesn't care or recognize any such meaning.

This bug report was last modified 1 year and 226 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.