;; Be careful with `map`, closures, and anonymous functions (defn typical-closure [] (let [names (atom [])] (fn [arg] (swap! names conj arg) @names))) ;; This works as expected: one function gets created and mapped (defmacro list-maker [fun args & body] `(defn ~fun ~args (map (typical-closure) '~body))) (list-maker foo [x] 1 2 3 4 5) (foo 100) ; ([1] [1 2] [1 2 3] [1 2 3 4] [1 2 3 4 5]) ;; This version recomputes the function for each mappand! (defmacro list-maker-oops [fun args & body] `(defn ~fun ~args (map #((typical-closure) %) '~body))) ;; facepalm (list-maker-oops foo [x] 1 2 3 4 5) (foo 100) ; ([1] [2] [3] [4] [5])
clojure.core, by purposeClojure String utilities It is poor form to (:use clojure.string).
This file defines a generic tree walker for Clojure data structures.
This file defines polymorphic I/O utility functions for Clojure.