[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: `when' vs. `and' / `unless' vs `or'

From: Garreau, Alexandre
Subject: Re: `when' vs. `and' / `unless' vs `or'
Date: Wed, 17 Oct 2018 00:38:54 +0200
User-agent: Gnus (5.13), GNU Emacs 25.1.1 (i686-pc-linux-gnu)

Le 16/10/2018 à 15h13, Drew Adams a écrit :
> Do whatever you like. ;-) Different people use different styles.
> There is no standard or even a convention. Common Lisp
> suggests some conventions, but there too there is nothing
> official.

What is this? it does interest me.

> I use `when' and `unless' when I want to show a human
> reader (mainly me) that the code doesn't use or care about
> the return value. I don't use them when the returned `nil'
> could be important.

Okay, so what about when you care about the result, but absolutely not
about the return value of the condition?

(unless cond body) vs (or cond body) -> `or' might imply you might want
to return cond.

> I use `and' or `or' when the return value is significant.
> (With `not' as needed.)
> I use `if' when the true part is a single sexp. If necessary,
> to respect this I flip the true and false parts (negating the
> condition).

So unless it is simple, you always write your big-conditions if as an
imbrication of both `or' and `and'? isn’t this actually less easy to
understand (even if easier to read with indentation)?

> I use `case' when the conditions would just test the
> same symbol for equality against different values.

And then comes typecase and its unability to have several types per
clause, or when you want to use an arbitrary test function for case, the
more likely and particular case of when you want that test function to
be `equal', the case where in your bodies you always apply something to
the aforementioned expr (so it looks redundant)…

> I use `cond' when I have two or more sexps for each of
> the true and false parts or I have more than two conditions.

…or the case each condition clause is actually to apply something to the
same thing.

I’ve refactored all this with my own typecase, case*, case-equal,
case-apply, case-test… Where case-apply is based on case-equal which is
based on case*, and typecase on case-test.  I still need to refactor all
this into a big general-case function upon everything is based by being
a particular case of it.

> I don't use `pcase' much. Nothing against it, really.

YMMV indeed :)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]