A year-and-a-half ago, Christophe Grand posted on his blog a cond variation
that supports the same :let notation that the for construct does (
http://clj-me.cgrand.net/2011/06/17/a-flatter-cond/). I have been using
this cond variation ever since he introduced it, and consider it to be the
#1 piece of useful syntactic sugar that Clojure does not currently have in
I saw today that let-> and some other threading macros are slated for
inclusion in 1.5. I thought this would be a good opportunity to raise
discussion about this, and formally suggest that Clojure's cond be modified
to allow :let clauses.
I am aware that there are other approaches which similarly prevent
interleavings of cond and let from getting overly indented (specifically,
Evan Gamble has an interesting variation of let that allows guards).
However, I advocate Grand's approach because of its elegant parallelism
with the syntax that already exists within the for construct. The notation
feels completely natural based on that existing precedent.
I should point out that the final version posted on Grand's site has a
couple additional features, specifically, his cond also supports a
:when-let clause and a final default clause that doesn't require :else.
Although I like these features, I am not advocating that those be added to
the core. Many people prefer to have the explicit check that their cond
has an even number of components and :when-let might not be intuitively
obvious as to what it does. So I am specifically recommending just to
include the support for :let clauses in cond and none of the other
features. This one addition shouldn't really break anyone's code, extends
cond in an intuitive way that is consistent with other Clojure constructs,
and is, in my experience, incredibly useful.