Now we know that dispatch on Clojure Protocols, strictly speaking, is dynamic.
We see here a fantastic example of compile-time dispatch using a macro:
(defmacro case+
"Same as case, but evaluates dispatch values, needed for referring to
class and def'ed constants as well as java.util.Enum instances."
[value & clauses]
(let [clauses (partition 2 2 nil clauses)
default (when (-> clauses last count (== 1))
(last clauses))
clauses (if default (drop-last clauses) clauses)
eval-dispatch (fn [d]
(if (list? d)
(map eval d)
(eval d)))]
`(case ~value
~@(concat (->> clauses
(map #(-> % first eval-dispatch (list (second %))))
(mapcat identity))
default))))
Here the writer argues that you will never be able to dispatch on return type in Clojure. To me it seems that with a sufficiently powerful macro, you can do anything.
My question is: Can we use macros to statically dispatch on a return type in Clojure?
case*macro have to do with the question? - amalloy