clojure-dev

seancorfield 2023-04-14T19:37:36.519159Z

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.

seancorfield 2023-04-14T19:38:31.904119Z

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?

borkdude 2023-04-14T19:39:44.164869Z

I wondered about this too

Alex Miller (Clojure team) 2023-04-14T20:27:18.448759Z

yeah, that should have been more scoped

Alex Miller (Clojure team) 2023-04-14T20:27:31.522809Z

my bad

borkdude 2023-04-14T20:28:07.153179Z

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) 2023-04-14T20:29:49.740719Z

that was another option considered, we chose this

seancorfield 2023-04-14T20:38:35.540599Z

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 😞

seancorfield 2023-04-14T20:42:10.587409Z

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

seancorfield 2023-04-14T20:43:57.131019Z

(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)

seancorfield 2023-04-14T20:44:13.072729Z

Anyways, this is why we have Alphas 🙂

Alex Miller (Clojure team) 2023-04-14T21:02:51.811559Z

yeah

seancorfield 2023-04-14T23:30:12.422949Z

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