Hanfei Sun
Hanfei Sun

Reputation: 47071

Why do I need to write (doc str) but (meta #'str)?

Why (doc str) but (meta #'str)?

In the latter one, why is the #' necessary, which isn't in the first one?

Upvotes: 3

Views: 123

Answers (2)

Ankur
Ankur

Reputation: 33657

doc is a macro which internally applies #' i.e var to the passed name, hence you don't need to pass the var itself to it. meta is a function and hence it needs the var itself to be passed otherwise the value of the var will get passed to it if you use just the name of the var (as done in doc)

Upvotes: 5

number23_cn
number23_cn

Reputation: 4629

#' is the reader macro, #'str expands to (var str), return the Var object, see doc:

user> (doc meta)
-------------------------
clojure.core/meta
([obj])
  Returns the metadata of obj, returns nil if there is no metadata.

Upvotes: 0

Related Questions