unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* `when' vs. `and' / `unless' vs `or'
@ 2018-10-16 21:05 Garreau, Alexandre
  2018-10-16 22:13 ` Drew Adams
  0 siblings, 1 reply; 11+ messages in thread
From: Garreau, Alexandre @ 2018-10-16 21:05 UTC (permalink / raw)
  To: help-gnu-emacs

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.



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2018-10-17 15:42 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-10-16 21:05 `when' vs. `and' / `unless' vs `or' Garreau, Alexandre
2018-10-16 22:13 ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).