This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-10-21
Channels
- # announcements (13)
- # babashka (29)
- # beginners (52)
- # calva (95)
- # cider (18)
- # clj-commons (7)
- # cljs-dev (42)
- # clojure (121)
- # clojure-australia (1)
- # clojure-dev (39)
- # clojure-europe (36)
- # clojure-france (4)
- # clojure-greece (1)
- # clojure-italy (20)
- # clojure-nl (3)
- # clojure-portugal (1)
- # clojure-uk (7)
- # clojurescript (47)
- # conjure (2)
- # cursive (9)
- # datalevin (5)
- # datascript (8)
- # datomic (68)
- # defnpodcast (2)
- # deps-new (5)
- # fulcro (18)
- # graalvm (21)
- # gratitude (9)
- # jobs (6)
- # jobs-discuss (17)
- # leiningen (3)
- # lsp (80)
- # lumo (1)
- # malli (9)
- # mount (2)
- # off-topic (16)
- # other-languages (8)
- # podcasts-discuss (19)
- # reitit (5)
- # remote-jobs (5)
- # shadow-cljs (29)
- # sql (5)
- # tools-deps (13)
- # vim (11)
- # xtdb (19)
@cfleming Hmm, nice edge case!
user=> (require '[clojure.set :as-alias set1 :as set2])
nil
user=> ::set1/foo
:clojure.set/foo
user=> ::set2/foo
:clojure.set/foo
user=> (set2/union #{1 2 3} #{4 5 6})
Syntax error compiling at (REPL:1:1).
No such var: set2/union
user=> (set1/union #{1 2 3} #{4 5 6})
Syntax error compiling at (REPL:1:1).
No such var: set1/union
user=> (clojure.set/union #{1 2 3} #{4 5 6})
Syntax error compiling at (REPL:1:1).
No such var: clojure.set/union
user=> (require 'clojure.set)
nil
user=> (clojure.set/union #{1 2 3} #{4 5 6})
#{1 4 6 3 2 5}
So what just happened there? Because the require has an :as-alias, the namespace isn’t loaded even though it also has an :as?
as-alias
and load
are handled mutually exclusive here:
https://github.com/clojure/clojure/commit/f96eef2892eaef55dbbdbf7f3b4b818be06f6ddd#diff-313df99869bda118262a387b322021d2cd9bea959fad3890cb78c6c37b448299R5958
so, if :as-alias
is used, then the namespace will not be loaded regardless of other options
Yeah, that should load
should both really be supported in one form? One upside of the exclusive requirements is how easy it is to implement eg https://github.com/weavejester/ns-tracker/commit/6f508d5022984aaab1d3647b9365597b48c8329c
It is simpler for them to be independent
it's the other way around: loading is the default behavior, but as-alias undoes this
yes, but then in your example (if Clojure changes the impl) as will undo the effects of as-alias again
It's not undoing. :as-alias alone does not require loading
previously you could not have multiple :as
either, so it might be reasonable to have :as
and :as-alias
exclusive.
user=> (require '[clojure.set :as s1 :as s2])
nil
user=> s1/union
Syntax error compiling at (REPL:0:0).
No such namespace: s1
user=> s2/union
#object[clojure.set$union 0x301ec38b "clojure.set$union@301ec38b"]
Yes, but that's a bug
We've already been down this road, this was a conscious decision
Fyi, the other place we considered disallowing something is in :use, which also uses load-lib
So you can :as-alias in :use, which is pretty weird, but will work
so going forward ns-tracker should look into supporting multiple as and as-aliases per require form and consider a ns loaded if there's either 1) no as-alias or 2) at least one as?
well, multiple :as
just results in inconsistent behavior since all opts are basically converted into a map
So, #1 - no :as-alias
#1: but if there is another :as, then it should be considered loaded - provided the bug gets fixed
I'm confused how https://clojurians.slack.com/archives/C06E3HYPR/p1634819427003800 and only #1 go together
since this is confusing and unnecessary I think I'm gonna make a rule to not use these two together in clj-kondo, unless someone comes up with a good use case (https://github.com/clj-kondo/clj-kondo/issues/1439)
To add a little more confusion, should :as-alias
+ :refer
also trigger a load? If not, then why should :as-alias
+ :as
trigger a load?
I logged this here and I'll take a look at it today
The example you pasted there was about a different issue/question: using :as
multiple times.
This is a better repro for the bug for that issue: https://clojurians.slack.com/archives/C06E3HYPR/p1634807003000600
oops, thx