source-fn is the function form of source: pass it a symbol naming a public definition, and it returns that definition's original source text as a string instead of printing it. section 22.3
Capture source as data
(require '[clojure.repl :refer [source-fn]]) (source-fn 'not-empty) ;; "(defn not-empty\n ...\n [coll] (when (seq coll) coll))" (println *1) ;; prints the captured definition section 22.3
(require '[clojure.repl :refer [source-fn]])
(source-fn 'not-empty) ; #1
;; "(defn not-empty\n \"If coll is empty, returns nil, else coll\"\n ; #2
;; {:added \"1.0\"\n :static true}\n [coll] (when (seq coll) coll))"
(println *1) ; #3
;; (defn not-empty
;; "If coll is empty, returns nil, else coll"
;; {:added "1.0"
;; :static true}
;; [coll] (when (seq coll) coll))
Inspect the complete returned string, including the definition, docstring, metadata, and argument form. section 22.3
Use source-fn when source needs to be captured, transformed, or inspected programmatically. Special forms and Java methods or classes do not provide retrievable source in this way. section 22.3
