liveBook · Manning

Source

As explained in Clojure: The Essential Reference

source is a Clojure macro that prints the original source text for a public definition.

source is a Clojure macro for inspecting the original source text of a public definition at the REPL. It belongs to clojure.repl, whose source- and environment-oriented tools complement documentation and exception utilities. section 22.3

Inspect a definition

(source unchecked-inc-int) ;; (defn unchecked-inc-int ;; "Returns a number one greater than x, an int." ;; {:inline ... :added "1.0"} ;; [x] (. clojure.lang.Numbers (unchecked_int_inc x))) The printed result exposes the definition, documentation, metadata, arguments, and implementation. section 22.3

Choose the related form according to the desired result:

  • Use source for direct, readable printing at the REPL. section 22.3
  • Use source-fn when the source text must be returned as a string for further manipulation or printing. section 22.3

How Clojure: The Essential Reference covers it

How deep it goes
Shows complete definition text, including documentation, metadata, parameters, and implementation, rather than merely naming a definition.
Examples
Prints the definition of unchecked-inc-int and contrasts it with source-fn applied to not-empty.
What you can do after
Evaluate source at the REPL to read a public definition’s implementation and metadata directly.
How it connects
Connects the REPL with macros, public definitions, clojure.repl, and source-fn.

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.