Last Updated: February 25, 2016
·
1.877K
· tonsky

Type hints in clojure macros

Type hints should be added to symbols. Here's how to do it for function's return type:

(defmacro defthreadlocal [name & body]
 `(def ~(with-meta name {:tag ThreadLocal})
    (proxy [ThreadLocal] []
      (initialValue []
        ~@body))))

And here's how to do it for args:

(defmacro declare-first-char []
  (let [s (gensym)]
   `(defn first-char [~(with-meta s {:tag String})]
      (.charAt ~s 0))))