This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-07-16
Channels
- # aws (17)
- # babashka (2)
- # beginners (131)
- # bristol-clojurians (1)
- # calva (16)
- # chlorine-clover (6)
- # cider (10)
- # clara (5)
- # cljsrn (82)
- # clojure (176)
- # clojure-dev (14)
- # clojure-europe (13)
- # clojure-italy (13)
- # clojure-nl (4)
- # clojure-spec (10)
- # clojure-sweden (32)
- # clojure-uk (32)
- # clojuredesign-podcast (2)
- # clojurescript (34)
- # community-development (2)
- # conjure (17)
- # cursive (4)
- # datomic (51)
- # emacs (6)
- # figwheel-main (26)
- # fulcro (16)
- # graalvm (11)
- # jobs (2)
- # jobs-discuss (30)
- # kaocha (4)
- # meander (23)
- # off-topic (34)
- # pathom (5)
- # re-frame (10)
- # reagent (3)
- # reitit (6)
- # releases (3)
- # sci (36)
- # shadow-cljs (27)
- # sql (9)
- # testing (6)
- # tools-deps (28)
- # vim (8)
I found this very surprising, that *ns*
is not bound in a require call. I discovered this when using *ns*
inside tests to setup various test databases, and all my databases where set to user
.
cat: src/my: No such file or directory
/t/stuff ❯❯❯ cat src/myns.clj
(ns myns)
(println (ns-name *ns*))
(defn foo []
(println (ns-name *ns*))
(println (namespace ::x)))
t/stuff ❯❯❯ clj
Clojure 1.10.1
user=> (require 'myns)
myns
nil
user=> (myns/foo)
user
myns
nil
user=> ^D
its dynamic. its set at load time but you aren't binding it. it seems like you just want (namespace ::x)
though
Ah, nice trick with (namespace ::x) — it’s within a macro which works at the REPL (because probably CIDER binds *ns*
for me?)
if the macro does it at compile time it should be the captured value you want. if it emits code to do it at run time it should be the same issue. I bet if you remove CIDER it still works
What I do if I want the current namespace name is this:
(def ^:private my-ns *ns*)
Then it is bound to the current ns when the compiler runs and my-ns
ends up with this namespace's name in it.