qx_52w
1.234K
· June 2012 ·
4188c62c28a196e3e82363217c56fca5

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))))
Sign in or sign up to add your response.
Featured Programming Job

Search all programming jobs