Fork me on GitHub
#babashka
<
2022-04-29
>
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?

borkdude15:04:03

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

borkdude15:04:51

Or do you need something else?

borkdude15:04:25

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

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.

borkdude15:04:58

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
lukasz15:04:06

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

lukasz15:04:46

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

borkdude15:04:01

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.

lukasz15:04:55

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