O'Reilly logo
  • Leandro Gonçalves de Oliveira thinks this is interesting:

3. In Chapter 5 you created a series of functions (c-int, c-str, c-dex) to read an RPG character’s attributes. Write a macro that defines an arbitrary number of attribute-retrieving functions using one macro call. Here’s how you would call it:

(defattrs c-int :intelligence
          c-str :strength
          c-dex :dexterity)


Cover of Clojure for the Brave and True


(defmacro defattrs [& args] (do ~@(map (fn [[name attribute]](defn ~name [obj#] (get obj# ~attribute))) (partition 2 args))))

(defattrs c-int :intelligence c-str :strength c-dex :dexterity)