Fork me on GitHub
#java
<
2022-01-12
>
João Galrito18:01:46

Hello! When requiring clojure namespace A from Java (and I assume it works the same in the REPL) that itself requires a clojure namespace B, what happens to A when namespace B is modified and reloaded?

João Galrito18:01:53

and also, what if I load namespace C that also depends on namespace B, but namespace B has changed since when namespace A was loaded

Alex Miller (Clojure team)18:01:54

on your first question - nothing

Alex Miller (Clojure team)18:01:28

on the second question, C will use the updated version of B

Alex Miller (Clojure team)18:01:39

I was kind of assuming you had done the first thing before the second, but a namespace will not be reloaded unless you explicitly request it to be - either by a direct load or by using the require :reload / or :reload-all for all transitive namespaces

Alex Miller (Clojure team)18:01:03

as a general thing, loaded code refers to other code via their var, and if the other code is reloaded, the var will be dereferenced to the new impl. that's generally how reloading works in Clojure at the repl etc

Alex Miller (Clojure team)18:01:51

(caveat, there are things the can make this not true - capturing the deref'ed value of a var, compiling with direct linking etc)

João Galrito18:01:15

so unless I required B from A with :reload, even if C is loaded with the new version of B, A will continue to use the old version of B?

Alex Miller (Clojure team)20:01:15

yes, reload only happens if requested

João Galrito20:01:59

alright, thank you @alexmiller 🙂

emccue20:01:23

does anyone have a clear understanding of why module-path and class-path are different values?

emccue20:01:53

like - if i were to just duplicate what is on the classpath to the module path what would the downside be

emccue20:01:19

java --class-path=... --module-path=...

Alex Miller (Clojure team)21:01:28

they are different approaches to declaring what classes are available to the JVM

Alex Miller (Clojure team)21:01:02

classpath (the "old" approach) is file-oriented and everything "merges" into one file tree conceptually

Alex Miller (Clojure team)21:01:41

the module-path chunks classes into modules and modules declare dependencies on other modules (and define additional visibility boundaries)

Alex Miller (Clojure team)21:01:57

I think the vision of modules (Java 9+) is that you specify everything as modules (so no classpath) but the reality is that not everything is a module. there are some rules to treat jars as automatic modules, but the middle place is kind of a messy world