This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # announcements (1)
- # babashka (6)
- # beginners (31)
- # calva (23)
- # cider (38)
- # clj-kondo (98)
- # cljs-dev (3)
- # clojure (56)
- # clojure-australia (2)
- # clojure-europe (14)
- # clojure-italy (1)
- # clojure-nl (2)
- # clojure-spec (17)
- # clojure-uk (27)
- # clojurescript (45)
- # code-reviews (1)
- # core-async (26)
- # core-logic (10)
- # cursive (11)
- # data-science (9)
- # datomic (7)
- # deps-new (4)
- # devcards (1)
- # emacs (4)
- # etaoin (2)
- # fulcro (14)
- # jobs (1)
- # kaocha (1)
- # leiningen (50)
- # malli (3)
- # parinfer (1)
- # pathom (7)
- # reitit (4)
- # remote-jobs (1)
- # reveal (45)
- # shadow-cljs (59)
- # sql (97)
- # tools-deps (1)
- # uncomplicate (4)
- # vim (18)
I just discovered that the following doesnt work.
(ns some-ns (:require [clojure.spec.alpha :as s])) (defn foo  (= (resolve 's/*) (resolve 'clojure.spec.alpha/*)))
foogets called by the application, the name space might not have required
[clojure.spec.alpha :as s]Instead, I did the following and it seems to work.
(ns some-ns (:require [clojure.spec.alpha :as s])) (defn foo  (binding [*ns* (find-ns 'some-ns)] (= (resolve 's/*) (resolve 'clojure.spec.alpha/*))))
You get different results than this in a REPL?
user=> (require '[clojure.spec.alpha :as s]) nil user=> (resolve 's/*) #'clojure.spec.alpha/* user=> (resolve 'clojure.spec.alpha/*) #'clojure.spec.alpha/* user=> (= (resolve 's/*) (resolve 'clojure.spec.alpha/*)) true
Note that you have no
clojure.spec.alpha/ I do not know if that is a typo in chat, or reflects your actual code.
yes a copy/paste error. corrected, should be /* everywhere
Now I see
clojure.spec.alpha. Did you intend to use
defn foo is in the namespace
some-ns ? If so, how does some part of your code call
foo without first require'ing
important observation is that the behavior of
resolve depends on the value of
foo is called, not when
foo is defined.
the caller of foo has required some-ns, but he might not have aliased closure.spec.alpha to s
Got it. Yes, that is true, and resolution of aliases like
s definitely depends upon the namespace in which they are resolved.
i found out because I ran my tests from the repl where I had required spec and aliased to s. But when I tested from
lien test at the comand line, it ran the tests with the
user namespace, which I never tested in.
s could be not an alias in some namespace, be used for
clojure.spec.alpha in another namespace, and be used for
clojure.set in yet another namespace. Not recommended for developer sanity to use the same alias for different namespaces, but Clojure allows it.
besides, when I develop the code, I use some convention. But I don't impose that convention on my customers who might have very different programming styles. or they theoretically might even be calling my code from java or some such
The doc string for
resolve gives a pretty strong hint about this dependence upon the current value of
I think all calls to resolve or suspect within code.. I'm thinking of refactoring every call in my program and replacing with ns-resolve so I'll have to think about which ns to use. Then test from repl and also from lein command line as a general pratice
it's on my to-do list.
ns-resolve instead of
resolve sounds like a good idea, if you want to force yourself to be explicit about in which namespace the resolving is performed.
of course nothing prohibits me from using
(ns-resolve *ns* foo) if that's the appropriate one to use.