Clojure 类型提示语法 [英] Clojure type hints syntax
问题描述
在Programming Clojure"一书中(Halloway, S.,(2009).Programming Clojure.Raleigh,NC:Pragmatic Bookshelf.)他使用语法显示了类型提示
In the book "Programming Clojure" (Halloway, S., (2009). Programming Clojure. Raleigh, NC: Pragmatic Bookshelf.) he shows type hints using the syntax
(defn describe-class [#^Class c]
...)
虽然在 Clojure 网站上,显示的类型提示没有 #
阅读器宏:
while on the Clojure Website, the type hints are shown without the #
reader macro:
(defn len2 [^String x]
...)
哪个是正确的?
推荐答案
两者都是,但在 Clojure 的不同版本中:从 1.2 版本开始,阅读器元数据的#^
语法(特别是,类型提示)已被弃用,而使用 ^
代替.请注意,#^
在 1.2 中仍然有效;还要注意 ^foo
在 1.2 之前是 (meta foo)
的简写,所以如果你使用旧的符号,你必须使用旧的符号发布.
Both are, but in different versions of Clojure: beginning with the 1.2 release, #^
syntax for reader metadata (in particular, type hints) is deprecated and ^
is to be used instead. Note that #^
still works in 1.2; also note that ^foo
was shorthand for (meta foo)
prior to 1.2, so you have to use the old notation if you use an older release.
这篇关于Clojure 类型提示语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!