I am trying to use clojure in a compiler and thus need to parameterize calls to deftype
; however, I am having difficulty making the type hints carry through. Consider the following code:
(defn describe [x]
(let [fields (.getDeclaredFields x)
names (map #(.getName %) fields)
types (map #(.getType %) fields)]
(interleave types names)))
(defn direct [] (deftype direct-type [^int x]))
(defn indirect-helper [] (list ^int (symbol "x")))
(defn indirect [] (eval `(deftype ~(symbol "indirect-type") ~(indirect-helper))))
And the following session from the REPL:
Clojure 1.2.0-master-SNAPSHOT
1:1 user=> #<Namespace dataclass>
1:2 dataclass=> (direct)
dataclass.direct-type
1:3 dataclass=> (indirect)
dataclass.indirect-type
1:4 dataclass=> (describe direct-type)
(int "x")
1:5 dataclass=> (describe indirect-type)
(java.lang.Object "x")
Notice that the generated class for indirect-type has lost the ^int hints that direct-type has. How do I get those hints to carry through?