From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: "Garreau\, Alexandre" Newsgroups: gmane.emacs.help Subject: `when' vs. `and' / `unless' vs `or' Date: Tue, 16 Oct 2018 23:05:11 +0200 Message-ID: <87o9btob5k.fsf@portable.galex-713.eu> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1539723838 25436 195.159.176.226 (16 Oct 2018 21:03:58 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 16 Oct 2018 21:03:58 +0000 (UTC) User-Agent: Gnus (5.13), GNU Emacs 25.1.1 (i686-pc-linux-gnu) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Oct 16 23:03:54 2018 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gCWVM-0006XG-SO for geh-help-gnu-emacs@m.gmane.org; Tue, 16 Oct 2018 23:03:53 +0200 Original-Received: from localhost ([::1]:60230 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCWXT-0002Cz-FE for geh-help-gnu-emacs@m.gmane.org; Tue, 16 Oct 2018 17:06:03 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33413) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCWWq-00029T-As for help-gnu-emacs@gnu.org; Tue, 16 Oct 2018 17:05:25 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gCWWl-0003Em-WC for help-gnu-emacs@gnu.org; Tue, 16 Oct 2018 17:05:22 -0400 Original-Received: from portable.galex-713.eu ([2a00:5884:8305::1]:41364) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gCWWg-000398-9k for help-gnu-emacs@gnu.org; Tue, 16 Oct 2018 17:05:17 -0400 Original-Received: from localhost ([::1] helo=portable.galex-713.eu) by portable.galex-713.eu with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gCWWd-0001MM-AJ for help-gnu-emacs@gnu.org; Tue, 16 Oct 2018 23:05:11 +0200 X-GPG-FINGERPRINT: E109 9988 4197 D7CB B0BC 5C23 8DEB 24BA 867D 3F7F X-Accept-Language: fr, en, it, eo X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:5884:8305::1 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:118284 Archived-At: Hi, TL;DR: I=E2=80=99m asking for opinions and individual practice, I=E2=80=99ve heard `when' and `unless' are for side-effects, because if cond fails they return nil (or maybe they don=E2=80=99t 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=E2=80=99m feeling like I should use a progn inside the `and'/= `or' (so I don=E2=80=99t bloat code)=E2=80=A6 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=E2=80=99m interested in your opini= ons 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.