This works, but I’m curious what the performance penalty is for dynamically passing in a namespace and resolving it using ns-resolve…
(ns bulbs.vertices)
(defn create
[config data]
((ns-resolve (:ns config) 'create-vertex) config data))
And then call it like this…
(ns bulbs.neo4jserver.graph
(:require [bulbs.vertices :as vertices])
(:require [bulbs.neo4jserver.client :as client]))
(defn graph
[& [config]]
(let [config (client/build-config config {:ns 'bulbs.neo4jserver.client})]
(fn [func & args]
(apply func config args))))
(def g (graph))
(g vertices/create {:name "James"})
unless your
ns-resolveis part of a loop (and unless you need to dynamically resolve a different function in every iteration there is absolutely no need for this), I wouldn’t worry about a performance penalty.But yes, there is a performance penalty:
If you really really really need the
ns-resolvemagic (but see the replies to your other question discouraging you from doing this in your particular situation), and if the function you’re resolving is used in a loop, take the resolve out of that loop: