ClojureDocs

Nav

Namespaces

meta

clojure.core

Available since 1.0 (source)
  • (meta obj)
Returns the metadata of obj, returns nil if there is no metadata.
3 Examples
(use 'clojure.pprint)
(pprint (meta #'first))
;;=> prints the following...
{:ns #<Namespace clojure.core>,
 :name first,
 :added "1.0",
 :file "clojure/core.clj",
 :static true,
 :column 1,
 :line 49,
 :arglists ([coll]),
 :doc
 "Returns the first item in the collection. Calls seq on its\n    
 argument. If coll is nil, returns nil."}
;; attach metadata to s.
;; ^:private is a shorthand notation for ^{:private true} and
;; ^String is a shorthand notation for ^{:tag java.lang.String}.
(def ^:private ^String s "Hello, world!")

;; inspect the metadata attached to s.
;; note, you need to use the var #'s, instead of the symbol s, as the argument.
(clojure.pprint/pprint (meta #'s))
;; =>
{:private true,
 :tag java.lang.String,
 :line 3,
 :column 1,
 :file "/tmp/form-init5430922801479403331.clj",
 :name s,
 :ns #object[clojure.lang.Namespace 0x13fca031 "user"]}
;; attach metadata to var x
(def ^{:version 1} x [1 2 3])

;; retrieve metadata of var x: note the notation
(meta #'x)
;; =>
{:version 1,
 :line 3,
 :column 1,
 :file "...",
 :name x,
 :ns ...}

;; attach metadata to an obj
(def y ^{:version 1} [1 2 3])

(meta y) ;=> {:version 1}
See Also

Returns an object of the same type and value as obj, with map m as its metadata.

Added by dnaumov

If set to logical true, when printing an object, its metadata will also be printed in a form that ...

Added by dnaumov

Returns an object of the same type and value as obj, with (apply f (meta obj) args) as its metadat...

Added by delonnewman
0 Notes
No notes for meta