On Thu, Mar 8, 2012 at 6:04 PM, Evan Gamble <solar.f...@gmail.com> wrote:

> That would work for replacing a single cond surrounded by a single
> let, but I often find myself writing a series of nested lets, when-
> lets, if-lets, etc. to handle the exceptional cases in lets. A
> contrived example:
>
> (when-let [a foo]
>  (let [b bar]
>    (when (even? b)
>      (let [c baz]
>         (when (> b c)
>            (let [d qux]
>               (f a b c d)))))))
>
> becomes:
>
> (let? [a foo :else nil
>       b bar :is even?
>       c baz :when (> b c)
>       d qux]
>  (f a b c d))
>
>
Right, I do run across this sort of nesting on a regular basis, and that's
the kind of thing that that bothers me.  With the cond macro, it would look
like:

(cond
  :when-let [a foo]
  :let [b bar]
  :when (even? b)
  :let [c baz]
  :when (> b z)
  :let [d gux]
  (f a b c d))

The cond is more faithful to the original structure and possibly more
versatile, but yours is nicely compact for the common case that the
interleaved statements are basically assertions on a given variable you
want to ensure before moving on.  I'm definitely going to give your let? a
try and compare it.  Thanks!

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to