Pau*_*Lam 10 clojure type-hinting
这两个似乎在Clojure中做同样的事情.哪种语法是规范的?
(defn a ^int [] 4)
(defn b ^{:tag int} [] 4)
Run Code Online (Sandbox Code Playgroud)
我希望它是a因为它更短.
我只b在需要包含除标签之外的元数据时使用.例如,在实现瞬态集合时,我需要
(deftype Whatever [^{:tag ITransientVector
:unsynchronized-mutable true} foo])
Run Code Online (Sandbox Code Playgroud)
请注意,编写它是等效的,完全可以接受
(deftype Whatever [^:unsynchronized-mutable ^ITransientVector foo])
Run Code Online (Sandbox Code Playgroud)
但我个人更喜欢显式地图.