liveBook · Manning

Symbol

As explained in Clojure: The Essential Reference

A Clojure symbol is a symbolic identifier that can name a var, local binding, or function parameter, appear as code data, carry metadata, and optionally include a namespace qualification.

A Clojure symbol is a symbolic identifier used to name vars, local bindings, and function parameters. Unlike a string, it can carry metadata, include a namespace qualification, and participate in code as data. When a symbol appears in an expression, Clojure looks it up in the current namespace or surrounding scope. section 15.1

Symbols have several practical properties:

  • Write a qualified symbol with a slash: a/b names b in namespace a. Use name and namespace to retrieve its two parts. section 15.1
  • Read Clojure forms as data to obtain symbols rather than evaluated values; macro evaluation also relies on this distinction. section 15.1
  • Attach metadata to symbols, although symbols are intended for program identifiers rather than general text. section 15.1
  • Create symbols with symbol or its two-argument constructor, but consult reader rules because constructors can bypass validation performed by literal syntax. section 15.1

Qualification changes identity

(def ax (symbol "a/x")) (def bx (symbol "b/x")) [(name ax) (name bx)] ;; ["x" "x"] (= ax bx) ;; false [(namespace ax) (namespace bx)] ;; ["a" "b"] Both symbols have the same name, x, but their namespace qualifications make them unequal. section 15.1

(def form (read-string "(a b)")) ; #1

(map type form) ; #2
;; (clojure.lang.Symbol clojure.lang.Symbol)

(defmacro reading-symbols [& symbols] ; #3
  `(map type '~symbols))

(reading-symbols a b) ; #4
;; (clojure.lang.Symbol clojure.lang.Symbol)

Inspecting a read form and a macro-produced form shows that identifiers remain clojure.lang.Symbol values before evaluation. section 15.1

How Clojure: The Essential Reference covers it

How deep it goes
Explains lookup, metadata, qualification, construction, and reader validation, but does not develop symbol internals beyond their Clojure class.
Examples
Uses symbol construction, namespace extraction, equality checks, read-string, and macro expansion to expose symbol behavior.
What it assumes
Assumes familiarity with Clojure expressions and namespaces while teaching the distinction between code identifiers, strings, and data.
What you can do after
Evaluate/understand how Clojure represents identifiers, resolves them, qualifies them, and preserves them in code data.
How it connects
Connects symbols with namespaces, vars, local bindings, function parameters, metadata, keywords, macros, and the reader.

Also explained in

Compare how 5 books explain symbol →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Clojure: The Essential Reference. The section links point to the parts of the book it draws on.