Your code does not do what you probably think. The tst function will print the value * ns *, var, during the execution of the function, and not when it is defined.
user> (ns foobar) nil foobar> (abc/tst) "test" #<Namespace foobar> nil foobar> (ns zelsbot) nil zelsbot> (abc/tst) "test" #<Namespace zelsbot> nil
What you are trying to do was already well presented by clojure.contrib.with-ns :
(ns xyz (:use clojure.contrib.with-ns)) (with-ns (create-ns 'abc) (defn tst [] (print "defined in namespace abc")))
It evaluates its body in the namespace that you provide as the first argument, which allows you to add functions to the namespace other than the current one.
source share