Fork me on GitHub
#clojure-dev
<
2023-04-14
>
seancorfield19:04:36

I'm looking at clojure.main and it seems that *repl* is bound to true in with-bindings, which is used for all :main-opts style invocations, I think? So add-lib is available in any process started with -M -- so -m some.ns, -e some.expr, etc all get *repl* true and can use add-lib. This seems necessary for use with nREPL/CIDER etc -- and thus it works with my :dev/repl code (that is invoked via -e and requiring-resolve) which is great -- but I just wanted to highlight that it's not "just in a REPL" in the bare clj sense.

seancorfield19:04:31

That also means that any (uber) JAR started via java -cp the.jar clojure.main -m my.entry.point will also have *repl* true I think and therefore could use add-lib?

borkdude19:04:44

I wondered about this too

Alex Miller (Clojure team)20:04:18

yeah, that should have been more scoped

borkdude20:04:07

what about just removing this var and just add warnings to the docstrings of clojure.repl/add-lib etc (clojure.repl already indicates that it's for REPL use only)

Alex Miller (Clojure team)20:04:49

that was another option considered, we chose this

seancorfield20:04:35

The trouble is, to make this work for most IDEs/editors, it really has to be available with -m because that's how "everyone" starts REPLs these days. Unless all of that tooling is updated to bind clojure.core/*repl* to true -- and we know how slow that tooling has been to adopt all of the other work around clojure.main such as exception/stacktrace handling 😞

seancorfield20:04:10

I think, perhaps, a JVM property that turns it off might be sufficient to address people's concerns?

seancorfield20:04:57

(I just posted a similar thought to Ask, but about disabling user.clj auto-loading since that seems to bite people a lot -- and in fact bit someone trying out add-lib today because invoke-tool still caused user.clj to get loaded, and it output stuff that broke the add-lib function somehow)

seancorfield20:04:13

Anyways, this is why we have Alphas 🙂

seancorfield23:04:12

> That also means that any (uber) JAR started via java -cp the.jar clojure.main -m my.entry.point will also have *repl* true I think and therefore could use add-lib? I was wrong about this: although such usage would have *repl* bound to true, starting the process via java means that the basis is not available and these features also assume they can shell out to the clojure command on the host -- so all of this new functionality is only available in processes started via the Clojure CLI itself, not via java.