6
我對使用with-meta
和^
閱讀器宏之間的差異感到困惑。with-meta vs^{} - Clojure
附上元太baz
symbol
用該閱讀器宏
user=> (def ^{:foo "bar"} baz {:my "value"})
#'user/baz
拉出來
user=> (meta #'baz)
{:foo "bar", :ns #<Namespace user>, :name baz, :line 1, :file "NO_SOURCE_PATH"}
連接使用with-meta
user=> (def (with-meta 'baz2 {:foo "bar"}) {:my "value"})
CompilerException java.lang.RuntimeException: First argument to def must be a Symbol, compiling:(NO_SOURCE_PATH:1)
然而
...
user=> (class (with-meta 'baz2 {:foo "bar"}))
clojure.lang.Symbol
我可以將它連接到值
user=> (def baz2 (with-meta {:my "value"} {:foo "bar"})
#'user/baz2
,但它是不一樣的
user=> (meta baz2)
{:foo "bar"}
user=> (meta #'baz2)
{:ns #<Namespace user>, :name baz2, :line 1, :file "NO_SOURCE_PATH"}
有人能解釋一下嗎?