ryoakg
5/26/2016 - 2:25 PM

macro-defining-macro.clj

(defmacro def-*with-precision*-n [n]
  (let [name (symbol (str "with-precision-" n))
        body (gensym)]
    `(defmacro ~name [& ~body]
       `(with-precision ~~n
          ~@~body))))
;;; or
(defmacro def-*with-precision*-n [n]
  (let [name (symbol (str "with-precision-" n))]
    `(defmacro ~name [& body#]
       `(with-precision ~~n
          ~@body#))))

(def-*with-precision*-n 7)
(with-precision-7 (/ 1M 3)) ;; => 0.3333333M

(def-*with-precision*-n 5)
(with-precision-5 (/ 1M 3)) ;; => 0.33333M