Fork me on GitHub
#clojure-dev
<
2021-10-19
>
souenzzo13:10:42

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?

borkdude13:10:23

: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.

souenzzo13:10:35

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

borkdude13:10:03

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

souenzzo13:10:09

I tested locally and it works without any warn.

borkdude13:10:18

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

borkdude13:10:27

also because create-ns doesn't load any code

borkdude13:10:59

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

borkdude13:10:16

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

souenzzo13:10:21

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

borkdude13:10:35

@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
dnolen15:10:03

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

cfleming23:10:57

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