From: "Garreau\, Alexandre" <galex-713@galex-713.eu>
To: help-gnu-emacs@gnu.org
Subject: `when' vs. `and' / `unless' vs `or'
Date: Tue, 16 Oct 2018 23:05:11 +0200 [thread overview]
Message-ID: <87o9btob5k.fsf@portable.galex-713.eu> (raw)
Hi, TL;DR: I’m asking for opinions and individual practice,
I’ve heard `when' and `unless' are for side-effects, because if cond
fails they return nil (or maybe they don’t return in some lisps or
previous emacsen?).
However, there are situations where I could use respectively `and' or
`or' instead, where these works and are not used for side-effects (there
may be none) but only for return value. Especially anywhere a boolean
is expected, as then nil has full meaning (the condition, or maybe the
body, failed).
Such as: (or stuff (when cond body) stuff) vs. (or stuff (and cond body)
stuff), or (and stuff (unless cond body) stuff) vs. (and stuff (unless
cond body) stuff), but also as a condition for an `if', or even another
`when' or `unless'. Then what should I do?
Should I ban these and only use `when' and `unless' for side-effects,
except when I’m feeling like I should use a progn inside the `and'/`or'
(so I don’t bloat code)… or maybe should I use that progn, to convey
some meaning (this one at least truly is for side-effects)?
Or should I use `when' and `unless' as much as possible, and use `or'
and `and' only when the first argument could be a meaningful non-nil
thing to return?
Maybe there are even other practices. I’m interested in your opinions
and your practices, as both manual and docstrings are not verbose enough
about this issue.
PS:
Personally, I was always seduced by how primitive and basic or
short-circuiting logical constructs, and never understood why these are
implemented in terms of conditionals, rather than the opposite (probably
because in imperative programming short-circuiting is quite relevant and
not trivial and the important thing of the if?), since these are backed
down in primitive logic.
So I tend to like to use them when I can, but I fear this is `(or
cryptical pedantic "a too-smart approach")', as first time I saw them
used like that I bugged a bit (but I can imput that to how and where I
was wrongly teached to see these).
PPS: Sorry for verbosity, one day I need to find a technique to fix that
PPPS: I fear I already asked something among those line a long time ago
but lost both the backup and memory of what was said.
next reply other threads:[~2018-10-16 21:05 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-16 21:05 Garreau, Alexandre [this message]
2018-10-16 22:13 ` `when' vs. `and' / `unless' vs `or' Drew Adams
2018-10-16 22:38 ` Garreau, Alexandre
2018-10-16 23:21 ` Drew Adams
2018-10-17 0:02 ` Garreau, Alexandre
2018-10-17 0:16 ` Drew Adams
2018-10-17 1:25 ` Garreau, Alexandre
2018-10-17 1:58 ` Drew Adams
2018-10-17 9:00 ` Garreau, Alexandre
[not found] ` <mailman.2299.1539766826.1284.help-gnu-emacs@gnu.org>
2018-10-17 9:49 ` Emanuel Berg
2018-10-17 15:42 ` Michael Heerdegen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87o9btob5k.fsf@portable.galex-713.eu \
--to=galex-713@galex-713.eu \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.