Hello,

I'm reading /Clojure in Action/, and I'm confused by one of the
examples.  I'm hoping someone can clarify it for me. :-)

The author gives an example of an assertion macro:

(defmacro assert-true [test-expr]
  (let [[operator lhs rhs] test-expr]
    `(let [lhsv# ~lhs rhsv# ~rhs ret# ~test-expr]
      (if-not ret#
        (throw (RuntimeException.
                       (str '~lhs " is not " '~operator " " rhsv#)))
        true))))

This can be used in this manner: (assert-true (< 4 3)), which will
raise an exception, since 4 is not less than 3.

What I do not understand is why he does not need to use gensyms in the
first let form (i.e., (let [[operator# lhs# rhs#] test-expr] ... ) .

By my understanding, I would expect

(let [rhs
3]
           (assert-true (= rhs 4)))

To incorrectly fail to assert due to "rhs" being captured.  However,
it works the way the author intends (i.e., it raises an exception.)

Why does "rhs" not get captured?

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