Fork me on GitHub

clojure 1.11 will allow "circular deps" via as-alias ?

Alex Miller (Clojure team)13:10:36

I don't think it allows anything new, can you explain?


:as-alias doesn't load the namespace, it only ensure the existence of the ns object in the clojure runtime. so it won't trigger a circular loading of namespaces.


(ns a (:require [b :as-alias b])) (prn ::b/ok) (ns b (:require [a :as-alias a])) (prn ::a/ok)


try that and you will see that you won't get a warning about circular namespaces


I tested locally and it works without any warn.


:as-alias is based on create-ns and create-ns does nothing if the namespace exists. this is why it works out ok


also because create-ns doesn't load any code


so previously people wrote (alias 'foo (create-ns 'bar))


that is now encoded in :as-alias , the implementation is similar


One last question: I can say that this is a feature? Or it works by a implementation detail and may not be supported in the future (or not ported to cljs/other targets)?!

Alex Miller (Clojure team)13:10:10

I'd say it's not even a feature - there is no loading happening so it's not allowing anything new in that respect

Alex Miller (Clojure team)13:10:37

how or whether it will work in CLJS is a question for @dnolen


@souenzzo a fun implementation detail. there is a var in clj called *loaded-libs* . at the and of the ns form this is conj-ed on to. After that another require of that ns won't trigger any loading. But this is handled separately from creating namespaces with create-ns , it's an extra thing for a ns to be considered already loaded

👍 1

thinking about it briefly it can probably work for ClojureScript, yes - none of reified ns stuff I think is needed

Alex Miller (Clojure team)16:10:25

yeah, it's probably easier in CLJS, it's just name resolution really


Am I right in thinking that there’s no good reason to use :as and :as-alias in the same require?