Where developers come to connect, share, build and be inspired.

0

Type hints in clojure macros

700 views

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))))

Comments

Add a comment