Fork me on GitHub
fogus (Clojure Team)14:04:52

Playing around with bb today creating a little language interpreter and found that I don't have access to the clojure.main ns nor the babashka.impl.clojure.main ns to leverage the existing REPLs. Rather than write my own REPL (which I'm not opposed to of course) I'd love to use the ones available if possible. Any insights?


Hey @U050WRF8X! Babashka exposes clojure.main/repl to scripts. Would that be sufficient?


Or do you need something else?


$ bb -e '(clojure.main/repl :init (fn []))'

fogus (Clojure Team)15:04:12

Ah yes. I see that now. I read my error too hastily. It's actually complaining about clojure.main/repl-read but I suppose I can use read directly or wrap it a little if needed.


clojure.main/repl might not work exactly the same as in JVM Clojure, but if you find bugs/need support, we can get that fixed and you can try a development binary

fogus (Clojure Team)15:04:29

OK! using the default reader works.

🎉 1

Is there some sort of a var that I can use in a bb script to detect if bb interpreter has running nrepl server vs just running a script? The use case is that I want to use script's functions in a bb nrepl session, and prevent the script from running System/exit


ah yeah, I should have thought about this in a more traditional way


It may not be sufficient for all cases though, e.g. I'm not sure if it would work if invoked from tasks. In general you can make your own dev? var which you set in the REPL to prevent anything else from happening.


Thanks, the suggested approach works :thumbsup: We're not using tasks yet, but it's one of the things I'm actively looking at