Skip to content

Instantly share code, notes, and snippets.

@Licenser
Created March 9, 2010 22:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Licenser/327199 to your computer and use it in GitHub Desktop.
Save Licenser/327199 to your computer and use it in GitHub Desktop.
(defn extract-fns
([ignores data]
(if (seq? data)
(lazy-seq
(let [data (macroexpand data)]
(let [f (first data)
data (rest data)]
(cond
(= f 'fn*) (let [data (first data)
locals (first data)
body (rest data)
ignores (set (concat ignores locals))]
(apply concat [f] (map (partial extract-fn ignores) body)))
(= f 'let*) (let [bindings (first data)
locals (take-nth 2 bindings)
bindings (rest (take-nth 2 (cons nil bindings)))
inner-ignores (set (concat ignores locals))
body (rest data)]
(apply concat [f] (map (partial extract-fns ignores) bindings) (map (partial extract-fns inner-ignores) body)))
true (apply concat [f] (map (partial extract-fns ignores) data))))))
(if (and
(symbol? data)
(not (ignores data)))
[data])))
([data]
(filter #(not (nil? %))
(if (and (seq? data) (seq? (first data)))
(distinct (apply concat (map (partial extract-fns #{}) data)))
(distinct (extract-fns #{} data))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment