This page summarizes some of Clojure's key concepts regarding metadata. It also provides links to more detailed information.

Symbols and collections support metadata, a map of data about the symbol or collection. The metadata system allows for arbitrary annotation of data. It is used to convey information to the compiler about types, but can also be used by application developers for many purposes, annotating data sources, policy, etc.

An important thing to understand about metadata is that it is not considered to be part of the value of an object. As such, metadata does not impact equality (or hash codes). Two objects that differ only in metadata are equal.

That said, metadata and its relationship to an object is immutable - an object with different metadata is a different object.


Predefined Keys

Here are some common metadata keys, adapted from Programming Clojure, 2e:

  • :arglists - argument lists, used by doc
  • :doc - documentation string, used by doc
  • :file - name of source file
  • :line - line number in source file
  • :macro - true for macros
  • :name - local name
  • :ns - namespace
  • :private - not intended for external use
  • :tag - expected argument or return type

User-defined Keys

Here are some other ways keys might be used:

  • org.junit.Test - set a Java annotation
  • :tainted - indicate tainted data

This wiki page is maintained by Rich Morin, an independent consultant specializing in software design, development, and documentation. Please feel free to email comments, inquiries, suggestions, etc!

Topic revision: r4 - 03 Mar 2013, RichMorin
This site is powered by Foswiki Copyright © by the contributing authors. All material on this wiki is the property of the contributing authors.
Foswiki version v2.1.6, Release Foswiki-2.1.6, Plugin API version 2.4
Ideas, requests, problems regarding CFCL Wiki? Send us email