I see what promises to be a nifty tool for anybody writing defn-like macros in the clojure.tools.macro library: the name-with-attributes function. The docstring says:
To be used in macro definitions. Handles optional docstrings and attribute maps for a name to be defined in a list of macro arguments. If the first macro argument is a string, it is added as a docstring to name and removed from the macro argument list. If afterwards the first macro argument is a map, its entries are added to the name's metadata map and the map is removed from the macro argument list. The return value is a vector containing the name with its extended metadata map and the list of unprocessed macro arguments.
But I can't seem to find an example that uses this function anywhere.
So, how can I use this function to define, say, a defn2 macro, which should be a clone of clojure.core/defn that contains all the same features, including:
- docstrings
- attribute maps
- preconditions
- multi-arities