Clojure - vary-meta


Advertisements

Returns an object of the same type and value as the original object, but with a combined metadata.

Syntax

Following is the syntax.

(vary-meta obj new-meta)

Parameters − ‘obj’ is the object which needs to be checked if any metadata is associated with it. ‘new-meta’ is the metadata values which needs to be associated with the object.

Return Value − Returns an object of the same type and value as the original object, but with a combined metadata.

Example

An example on how this is used is shown in the following program.

(ns clojure.examples.example
   (:gen-class))
(defn Example []
   (def my-map (with-meta [1 2 3] {:prop "values"}))
   (println (meta my-map))
   (def new-map (vary-meta my-map assoc :newprop "new values"))
   (println (meta new-map)))
(Example)

Output

The above program produces the following output.

{:prop values}
{:prop values, :newprop new values}
clojure_metadata.htm
Advertisements