Re: Macro for quickly switching libraries

2016-04-16 Thread Will Bridewell
Thanks for this. Gives me a much better idea of where to start. This is the 
second time that I've run across a need to switch libraries on the fly, so I 
figure it's time to work out a better approach. 

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Macro for quickly switching libraries

2016-04-05 Thread Will Bridewell
I'm working on some code where I want to evaluate different implementations 
of the same functionality. Each implementation of a function lives in its 
own namespace. For example, suppose that I have the following simplified 
code.

(ns tst1)
(defn foo [x] (+ x 1))

(ns tst2)
(defn foo [x] (+ x 2))

(ns tst3)
(defn foo [x] (+ x 3))

(in-ns 'user)

What I'd like to do is call a macro that binds the function name in user to 
the function in one of the libraries. The call would look like one of 
these. 

(switch-library! 'tst1 'foo)

(switch-foo-library! 'tst1)

The closest that I got was to do 

(defmacro switch-foo-library! [x]
  `(defn foo [y#] ((resolve (symbol (str ~x "/foo"))) y#)))

That's kind of embarrassing, but I think it does what I want. However, 
suppose I do

(ns-unmap 'user 'juxt)
(defmacro switch-juxt-library! [x]
  `(defn juxt [y#] ((resolve (symbol (str ~x "/juxt"))) y#)))

Now I get 

CompilerException java.lang.RuntimeException: Can't create defs outside of 
current ns, compiling:

Well, gosh. I can't play around with symbols in clojure.core? What's 
happening here?


-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.