Back
source-fn (clj)
(source)function
(source-fn x)
Returns a string of the source code for the given symbol, if it can
find it. This requires that the symbol resolve to a Var defined in
a namespace for which the .clj is in the classpath. Returns nil if
it can't find the source. For most REPL usage, 'source' is more
convenient.
Example: (source-fn 'filter)
Examples
cognitect/clojure-lab
;; @@
(require '[clojure.repl :refer :all])
;; @@
;; @@
(dir clojure.repl)
;; @@
;; ->
;;; apropos
;;; demunge
;;; dir
;;; dir-fn
;;; doc
;;; find-doc
;;; pst
;;; root-cause
;;; set-break-handler!
;;; source
;;; source-fn
;;; stack-element-str
;;; thread-stopper
;;;
;; <-
;; =>
;;; {"type":"html","content":"<span class='clj-nil'>nil</span>","value":"nil"}
;; <=
plumatic/grab-bag
(ns tubes.macros
(:require
[clojure.repl :as repl]))
(defmacro import-vars [ns & syms]
`(do
~@(for [sym syms]
(read-string (repl/source-fn (symbol (name ns) (name sym)))))))