I wanted to have some functions run when an app starts, and I wanted this 
to be configurable, because I plan to use the same architecture for several 
apps. So I thought I could have the function names as strings inside of 
maps inside of a set (that I sort), in a config file. And I thought I could 
use ns-resolve *ns* symbol to turn the strings into references to the vars 
where the function definitions are stored. But somehow this is not working. 
I have this right now, in mpdv.core, which is the core namespace is an app 
I created with lein:


(defn process-startup-hooks []
  "2013-02-21- remember, each row in hooks is a map: {:order-of-events 1, 
:event-name 'connect-to-database'}"
  (connect-to-database)
  (let [hooks (sort-by :order-of-events 
(:events-called-when-the-app-starts-hooks @um/interactions))]
    (doseq [x hooks]
      (let [event-as-symbol (symbol (:event-name x))
            event (ns-resolve *ns* event-as-symbol)]
        (println " what kind of var is this? ")
        (println *ns*)
        (println (type event-as-symbol))
        (println event-as-symbol)
        (if-not (nil? event)
          (event))))))


"event" is always nil. One of the events listed in um/interactions is 
"connect-to-database" so, as a test, I hardcoded it here, to be sure it 
could run here, and it runs fine (first line after the comment). So the var 
for the function is known. But this:

(ns-resolve *ns* event-as-symbol)

returns nil, even when event-as-symbol is "connect-to-database". 

When I println *ns* to the terminal output, I see the namespace is: 

#<Namespace clojure.core>

Which surprises me somewhat. 

How do I get ns-resolve to look in mpdv.core for the var that I want it to 
find? 

-- 
-- 
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/groups/opt_out.


Reply via email to