问题描述
在编程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]
...)
在上,类型提示显示时没有#
阅读器宏:
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类型提示语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!