Fork me on GitHub
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")


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

👍 2

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


You may also want to try bb -x:

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


in tasks:

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

💯 2

You can also use

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