On Fri, Jan 04, 2013 at 08:58:40AM +0100, Tassilo Horn wrote:

At least in my experience, it usually matters a lot which form actually
evaluated to nil.  But it's easy to write a macro `if-let-all' or so,
which would expand into

 (let [x 1 y nil z 3]
   (if (and x y z)
     (+ x y z)
     0))

if you really feel a need for it.

Seems like it's be a lot more useful to expand that to:

  (let [x 1]
    (if x
      (let [y nil]
        (if y
          (let [z nil]
            (if z (+ x y z)
              else-clause))
          else-clause))
    else-clause))

With maybe a fn thrown in to avoid repeating the else-clause.  This
allows constructs where successive values need to be computed, that
depend on the previous, and if we get a nil, we need to stop.

It's especially useful when interfacing with Java code with things
that really like to return nil on errors, and raise exceptions if you
pass the nil to the next step.

David

--
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