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
its core.
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.
You could add a patch to CLJ-200 and see if it gets screened. All patches for tickets that aren't closed go through my prescreening process, but that is only gets it on the big list of prescreened patches, with all of the others.
> 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 its core.
> 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.
> You could add a patch to CLJ-200 and see if it gets screened. All patches
> for tickets that aren't closed go through my prescreening process, but that
> is only gets it on the big list of prescreened patches, with all of the
> others.
> It would be polite if it the patch lists the name of the author of the
> code submitted.
> Andy
> On Nov 15, 2012, at 3:24 PM, Mark Engelberg wrote:
> 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
> its core.
> 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.
> --Mark
> --
> You received this message because you are subscribed to the Google Groups
> "Clojure Dev" group.
> To post to this group, send email to clojure-dev@googlegroups.com.
> To unsubscribe from this group, send email to
> clojure-dev+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/clojure-dev?hl=en.
And since it is Thanksgiving in the USA, I wanted to thank the real creators of that page: Christopher Redinger and Stuart Halloway. I've added some and rearranged it, but most of it was there before I ever touched it.
And thanks to Rich Hickey for writing and releasing Clojure into the world, and for all of the other folks who've made it better and built libraries and applications on top of it.
Andy
On Nov 23, 2012, at 12:39 AM, Mark Engelberg wrote: