Skip to content
marick edited this page Oct 22, 2011 · 2 revisions

This feature is available in 1.3-alpha5. It is experimental.

In some versions of Lisp, if was a macro that expanded into cond, something like this:

(defmacro my-if [test true-branch false-branch]
  `(cond ~test ~true-branch :else ~false-branch))

There are (at least!) two ways of testing such a macro. You can test that code that uses it behaves correctly. (Does it take the true branch when the test is true? The false branch otherwise?) You can also expand a form with the macro and check that the right expansion is produced. The =expands-to=> arrow helps you do that:

(fact
  (my-if (odd? 1) 1 2) =expands-to=> (clojure.core/cond (odd? 1) 1 :else 2))

This was inspired by Let Over Lambda. Should there be text about that here?

Clone this wiki locally