Fork me on GitHub
#babashka
<
2023-03-12
>
Peter Tonner17:03:15

this is more a general clojure question but I'm trying to use it in babashka: what is the right way to programatically call a function from a namespace? context is trying to right a "tool" task that takes a function name as an argument, and then calls the corresponding function from the tools namespace. I was playing around with building the function symbol with symbol but can't figure out how to call the function that the symbol is referencing

Peter Tonner17:03:24

oh may have figured it out with something like

((->> (first *command-line-args*)
                    (symbol "tools")
                    resolve))

lukasz17:03:39

(when-let [f (requring-resolve (symbolfoobar.tool/bananas"))] (f args))

👍 2
lukasz17:03:37

omg, can't Slack this morning facepalm , anyway - requiring-resolve is what you want most likely

borkdude18:03:44

You may also want to try bb -x:

bb -x tools/your-function --foo 1 --bar 2

borkdude18:03:24

in tasks:

{:task (exec 'tools/your-function)
 :exec-args {:foo 1 :bar 2}}

💯 2
borkdude18:03:44

You can also use

bb -m tools/your-function
which calls your function with command line args