I tend to have this at the top of most of my namespaces: (def ^:private my-ns *ns*)
This evaluates *ns* at load/init time when it is bound to the namespace being loaded and then initializes my-ns with that value. Then I use my-ns throughout that namespace. *ns* is dynamically bound to whatever namespace is currently executing which is why it changes "unexpectedly" when you're trying to do something obvious with it. On Thu, Feb 21, 2013 at 10:30 AM, larry google groups <[email protected]> wrote: > 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 [email protected] > Note that posts from new members are moderated - please be patient with your > first post. > To unsubscribe from this group, send email to > [email protected] > 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 [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. > > -- Sean A Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ World Singles, LLC. -- http://worldsingles.com/ "Perfection is the enemy of the good." -- Gustave Flaubert, French realist novelist (1821-1880) -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] 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 [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
