Fork me on GitHub
#babashka
<
2021-01-29
>
Daniel Stephens18:01:59

hi there, thanks for an amazing tool! I see in the github readme it says a few java classes that are available for interop, https://github.com/babashka/babashka#goals I was wondering what dictates that selection of supported things, is it a manual process to support each new class? Specifically I was reading through https://vlaaad.github.io/tools-cli-in-10-lines-of-code and thought about trying it in babashka but the clojure.lang.Compiler isn't present so some bits in the help script don't work. It was just a toy so I'm not too fussed and I can write something to add the docs to the metadata but I was interested in what changes what's available. Thanks!

borkdude18:01:59

@dstephens The included classes dictate what you can do with interop, that is correct. We don't include clojure.lang.Compiler since this is generally not something you should probably need for scripting. The function demunge he is using is available in both clojure.repl and clojure.main:

$ bb -e '(clojure.main/demunge "foo_bar")'
"foo-bar"
$ bb -e '(clojure.repl/demunge "foo_bar")'
"foo-bar"

borkdude18:01:26

So probably you can port it using those functions

borkdude18:01:44

btw, tools.cli is also available in bb

borkdude18:01:16

@dstephens I'm not sure why @vlaaad defines the help function like this:

(defn help [f]
  (println (:doc (meta (resolve (symbol (Compiler/demunge (.getName (class f)))))))))
since there is already clojure.repl/doc which does the same thing, except that it is a macro. Maybe that is his reason.

vlaaad20:01:27

Because that's not a macro :P

borkdude18:01:54

The function equivalent of clojure.repl/doc would be:

bb -e '(clojure.repl/print-doc (meta (var inc)))'

borkdude18:01:32

or:

$ bb -e "(clojure.repl/print-doc (meta (resolve 'inc)))"

Daniel Stephens18:01:06

Ahh thanks, that's very interesting, yeah I did try with doc as my initial thought but it didn't pan out. Ohh nice, I'll give that a shot. As you point out, I'm pretty happy to use tools.cli as well, but it's fun experimenting 👍