Welcome! Please see the About page for a little more info on how this works.

+1 vote
in Compiler by

Primitive functions only work (e.g. return primitive types) when defined with defn. An equivalent function created with fn does not behave the same way as when created with defn. For example:

(definterface IPrimitiveTester
(getType (link: ^int x))
(getType (link: ^long x))
(getType (link: ^float x))
(getType (link: ^double x))
(getType (link: ^Object x)))

(deftype PrimitiveTester (link: )
IPrimitiveTester
(getType (link: this ^int x) :int)
(getType (link: this ^long x) :long)
(getType (link: this ^float x) :float)
(getType (link: this ^double x) :double)
(getType (link: this ^Object x) :object))

(defmacro pt (link: x)
`(.getType (PrimitiveTester.) ~x))

(defn with-defn ^double (link: ^double x)
(+ x 0.5))

(pt (with-defn 1.0)) ; => :double

(let (link: a (fn ^double [^double x) (+ x 0.5))]
(pt (a 0.1))) ; => :object

Please see the discussion on the mailing list for more details and thoughts on what is happening:
http://groups.google.com/group/clojure/browse_thread/thread/d83c8643a7c7d595?hl=en

1 Answer

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJ-919 (reported by alex+import)
...