(resolve (symbol f)) works at the REPL but not in an uberjar

60 views
Skip to first unread message

lawrence...@gmail.com

unread,
Oct 12, 2017, 9:27:06 PM10/12/17
to Clojure
At the REPL, this works perfectly:

 > (defn get-users [] [:susan :kwan])
 > 
 > (defn what-is-this-function [f] ((resolve (symbol f))))
 
 > (what-is-this-function "get-users")
 >[:susan :kwan]
 
In an uberjar this does not work. I read somewhere that the runtime name-space is different than the REPL namespace and different from the namespace that exists while the compiler compiles the code. 

So how do I resolve the symbol correctly? 

I have functions that call a MySQL database, and each function is named after a database table. Most of the mechanics of the call are the same, the only thing different is the SQL. So I have functions such as "company" and "user" and "product". I also have a function called (select). I call select with one of the other functions, given as a string: 

(select "product")

Inside of (select) I need to turn "product" into a resolved symbol that I can call. 

Afterwards, I store the results in a map in an atom. I want to use the database names as the keys. So "product" should be the key that holds the results of the function "product". 

But what I need to do to correctly resolve the string to a function? 





lawrence...@gmail.com

unread,
Oct 12, 2017, 9:34:03 PM10/12/17
to Clojure
Nevermind. I found that this works, though I think it is ugly and inelegant: 

         resolved-f (resolve (symbol (str "denormalize.pull-from-mysql/" f)))

Justin Smith

unread,
Oct 12, 2017, 9:54:36 PM10/12/17
to clo...@googlegroups.com
you can use (symbol "denormalize.pull-from-mysql" "f") instead

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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+u...@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+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

lawrence...@gmail.com

unread,
Oct 13, 2017, 3:21:12 AM10/13/17
to Clojure
Is there a way I can avoid hard-coding " "denormalize.pull-from-mysql"" ? I guess it doesn't matter, but it does seem a little inelegant.

Gary Verhaegen

unread,
Oct 13, 2017, 7:00:47 AM10/13/17
to clo...@googlegroups.com
From the description of your problem, it's not really clear to me why you insist on using strings. Why not use the functions directly? Functions can serve as keys in maps. Granted, it's a bit ugly to print. You could also build a map of string to function yourself. Not sure what the performance of that would be compared to going through resolve every time; I would bet on "faster" but without much confidence.
clojure+unsubscribe@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+unsubscribe@googlegroups.com.

Isaac Tsang

unread,
Oct 13, 2017, 8:54:30 AM10/13/17
to Clojure
That because you REPL had set `*ns*`, when Clojure bootstrap from clojure.main, the *ns* bound to clojure.core
Reply all
Reply to author
Forward
0 new messages