Skip to content

Instantly share code, notes, and snippets.

@timmc
Created March 31, 2011 19:54
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 timmc/897116 to your computer and use it in GitHub Desktop.
Save timmc/897116 to your computer and use it in GitHub Desktop.
Sample macro to create multiple functions
(defmacro defconv
[a-symb b-symb num-expr]
(when-not (and (symbol? a-symb) (symbol? b-symb))
(throw (Exception. "defconv not given two symbols")))
(let [ab-symb (symbol (str (name a-symb) "->" (name b-symb)))
ba-symb (symbol (str (name b-symb) "->" (name a-symb)))]
`(let [num# ~num-expr]
(defn ~ab-symb [~'a] (* ~'a num#))
(defn ~ba-symb [~'b] (/ ~'b num#)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment