Advertisement
Guest User

macro

a guest
Mar 9th, 2011
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;; ^:dynamic  will be required to allow rebinding in Clojure 1.3
  2. (def *schema-imports*
  3.   (hash-map))
  4.  
  5. (defmacro with-schema-imports
  6.   "Executes body with schema elems (given as vector of symbol, keywords, or
  7. strings) imported and thus referrable by their simple name."
  8.   [elems & body]
  9.   (letfn [(keyval [qn]
  10.           (let [qstr (name qn)
  11.             lof (. qstr lastIndexOf ".")
  12.             sn (. qstr substring (inc lof))]
  13.             [sn qstr]))]
  14.     (let [keyvals (mapcat keyval elems)]
  15.       `(binding [*schema-elems* ~(apply assoc *schema-imports* keyvals)]
  16.      ~@body))))
  17.  
  18. ;; That works fine in the defining namespace, but in a different one (the test namespace) I get:
  19.  
  20. Unable to resolve var: funql.core/*schema-elems* in this context
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement