Fork me on GitHub
#clojure-dev
<
2021-10-21
>
cfleming09:10:48

Right, but I meant two aliases in the same require.

borkdude09:10:23

@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}

borkdude09:10:56

Seems like a bug if you ask me which should be fixed in alpha3

cfleming09:10:21

So what just happened there? Because the require has an :as-alias, the namespace isn’t loaded even though it also has an :as?

borkdude09:10:24

with a preference for as-alias

borkdude09:10:58

so, if :as-alias is used, then the namespace will not be loaded regardless of other options

mkvlr12:10:27

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

Alex Miller (Clojure team)12:10:00

It is simpler for them to be independent

borkdude12:10:05

I can make a linting rule in clj-kondo for that :-)

borkdude12:10:39

unless there are real use cases for having both

mkvlr12:10:14

having :as affect loading in this case feels strange to me

borkdude12:10:18

it's the other way around: loading is the default behavior, but as-alias undoes this

mkvlr12:10:50

yes, but then in your example (if Clojure changes the impl) as will undo the effects of as-alias again

Alex Miller (Clojure team)12:10:22

It's not undoing. :as-alias alone does not require loading

borkdude12:10:44

it's undoing the load of an :as if it's there

borkdude12:10:09

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"]

Alex Miller (Clojure team)12:10:06

We've already been down this road, this was a conscious decision

borkdude12:10:18

ok, bug it is then

Alex Miller (Clojure team)12:10:31

Fyi, the other place we considered disallowing something is in :use, which also uses load-lib

Alex Miller (Clojure team)12:10:12

So you can :as-alias in :use, which is pretty weird, but will work

borkdude12:10:47

let me check if clj-kondo does this correctly..

borkdude12:10:33

seems to work

mkvlr12:10:27

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?

borkdude12:10:44

well, multiple :as just results in inconsistent behavior since all opts are basically converted into a map

borkdude12:10:02

so don't rely on which one will win, the first or last one. just don't do it.

borkdude13:10:35

#1: but if there is another :as, then it should be considered loaded - provided the bug gets fixed

borkdude13:10:21

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)

borkdude13:10:39

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?

Alex Miller (Clojure team)13:10:10

I logged this here and I'll take a look at it today

borkdude13:10:35

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