On Fri, Jun 5, 2009 at 2:09 PM, Ragnar Dahlén <r.dah...@gmail.com> wrote:

>
> This turned out to be problematic since a couple of the commands have
> the same names as some clojure.core functions, most notably get and
> set.
>
> I solved this by checking if *ns* already contained a mapping for the
> name, and if so, ns-unmap:ing it.
>
> To use the functions, you would then have to (require 'redis), ie. not
> :use, and call them namespace qualified, ie.
>
> (redis/get "key")
> (redis/set "key" "value")
>
> First question: Is this a bad idea? How should you generally solve
> function name clashes? In this case, I really wanted to have the same
> name, not "redis-get" or something similar.


I believe what you are looking for is the :refer-clojure clause to ns. Use
it like this and you will no longer have to ns-unmap get and set:

(ns redis (:refer-clojure :exclude [get set]))

That will refer everything in clojure.core except for the get and set
functions.


> Second question: I tried AOT compiling my library, and packaging the
> class files into a JAR (check build.xml, jar target). However, when I
> try to use JAR file and (require 'redis) I get the following
> exception:
>
> Caused by: java.lang.IllegalStateException: keys already refers to:
> #'redis/keys in namespace: redis


I wonder if using the :refer-clojure clause will help with this, too.

Overall, I don't think it's bad form to use the names get and set and to
require calls to your functions to be namespace qualified.

HTH,

- J.

--~--~---------~--~----~------------~-------~--~----~
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