2024 Clojure状态调查!中分享您的想法。

欢迎!请访问关于页面了解有关此信息的一些更多信息。

+1
编译器

原始函数仅在用defn定义时才工作(例如,返回原始类型)。用fn创建的等效函数的行为不如用defn创建的函数相同。例如

(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

请查看邮件列表上的讨论,以获取更多细节和对此发生情况的想法。
http://groups.google.com/group/clojure/browse_thread/thread/d83c8643a7c7d595?hl=en

1 个答案

0
参考: https://clojure.atlassian.net/browse/CLJ-919(由alex+import报告)
...