nbb 2023-07-26

Using nbb to explore an API. I'm getting response data, converting it from json to edn via js->clj, and pprint'ing it. However, unlike js/console.log the output is all in one line in the repl. Guessing in some part due to my editor of choice, but is there a way to get the formatted output to show in the nrepl server process like js/console.log?

perhaps you can try (set! *print-fn* js/console.log) or so?

doesn't seem to work

user=> (alter-var-root #'prn (constantly js/console.log))
#object[log]
user=> (prn 1)
1
nil
user=> (prn #js [1 2 3]))
[ 1, 2, 3 ]
nil

Oh... wait I was using clj->js instead of js->clj 😵

It would still be helpful if println, prn, pprint, etc... could output to the main nrepl server proc like js/console.log does but this is a big improvement at least 😅

Ooh actually, I can write a userland function for that. Would just call with-out-str to pprint my data, then console.log the str output

Thinking it would be nice for keeping particular data visible on my terminal that doesn't update frequently

It works!

🎉 1

Is it possible to invoke nbb scripts from a parent directory and possibly tools like Shadow CLJS without having to run shell commands? I am investigating using nbb to unify some build tasks in a pure CLJS project, and I would like to avoid makefiles and shell scripts if I can.

Sure, you can use load-file in nbb and also you can use the Node libraries for spawning programs

Awesome! nbb.core/load-file is exactly what I wanted