I have come up with a solution to a problem I don't think exists outside of 
my mind, but since I can't for the life of me figure out how Clojure 
'wants' me to do this, I thought I would bounce this off the Google Group.

*The scenario:* I am trying to collect a bunch of functions and macros from 
all the different namespaces in my library into a single namespace; let's 
call the namespace adams-lib.api. The idea is that the consumer of the 
library will only have to include that one API namespace, and not all of 
the little namespaces with parts of the functionality.

*The problem:* Obviously, calling (use) doesn't cut it, because the aliased 
vars are not immigrated by subsequent calls to the (use) of the namespace 
that (used) them. You know what I mean.

*The "solution": *For functions this is simpler, but macros pose some 
additional challenges, which is why I'm including my "solution" for 
immigrating macros. Hold on to your hats, this one is ugly:

(defmacro immigrate-macro
  [ns-sym macro-sym]
  `(let [ nspublics# (ns-publics '~ns-sym)
          macro-var# (nspublics# '~macro-sym)
          macro-fn# @macro-var#
          macro-meta# (meta macro-var#)]
    (def ~macro-sym macro-fn#)
    (. (var ~macro-sym) (setMacro))
    (reset-meta! (var ~macro-sym) macro-meta#))
    nil)


And using it:

(immigrate-macro adams-lib.some-other-ns some-macro)


There has got to be a simpler/better/less insane way of doing this. Would 
anyone care to weigh in? For the record, I fully realize that my solution 
is not OK.

-Adam

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to