babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
Mno 2020-09-03T10:35:56.076400Z

oh wow

2020-09-03T12:09:43.077800Z

Is there any way to extend fipp’s IEdn protocol in babashka, to control pretty printing?

borkdude 2020-09-03T12:10:41.078500Z

Currently fipp is used as a stand-in for clojure.pprint because clojure.pprint didn't work well with GraalVM at the time. I'm not sure if we expose fipp itself as well

borkdude 2020-09-03T12:10:53.078900Z

But we might and then we could also expose more of it maybe

2020-09-03T12:12:41.079100Z

Just looking for a way to control pretty printing, or even printing

2020-09-03T12:13:40.079300Z

I’m trying to output a tagged literal for regexes

borkdude 2020-09-03T12:15:36.079500Z

Can you give an example?

borkdude 2020-09-03T12:17:03.079700Z

Of how you would do it on the JVM I mean

2020-09-03T12:17:38.079900Z

What I naively tried was

(extend-protocol fipp.ednize/IEdn
  java.util.regex.Pattern
  (-edn [x]
    (tagged-literal "regex" (pr-str x))))
I have an aero reader for a #regex tag, but need to be able to round trip values.

2020-09-03T12:18:22.080100Z

Let me see if that works on JVM

2020-09-03T12:19:55.080300Z

mm, doesn’t seem to do what I expected

borkdude 2020-09-03T12:23:06.080500Z

user=> (defmethod print-method java.util.regex.Pattern [v ^java.io.Writer w] (.write w (pr-str (tagged-literal 'regex (.pattern v)))))
#object[clojure.lang.MultiFn 0x6aef4eb8 "clojure.lang.MultiFn@6aef4eb8"]
user=> (clojure.pprint/pprint #"foo")
#regex "foo"

borkdude 2020-09-03T12:23:16.080700Z

something like this?

borkdude 2020-09-03T12:24:26.080900Z

You can also postwalk your data first and turn it into a tagged literal maybe, since overriding print-method for core types might not be a good idea. But it might be OK for scripts

borkdude 2020-09-03T12:25:06.081100Z

I'm surprised bb supports this btw, I didn't expect it :)

2020-09-03T12:25:30.081500Z

OK, I just need to explicitly call fipp.ednize/edn.

borkdude 2020-09-03T12:26:10.081700Z

what about the above?

2020-09-03T12:28:05.081900Z

postwalk is certainly a viable workaround. ednize isn’t working as it refers to ThreadLocal.

borkdude 2020-09-03T12:28:37.082100Z

What about the above print-method ?

2020-09-03T12:29:53.082300Z

Oh, sorry missed that. I thought I tried that before. Let me see

borkdude 2020-09-03T12:30:51.082500Z

It does work on my machine's bb

2020-09-03T12:32:25.082800Z

OK, sorry for the noise. That does indeed work nicely 🙂

borkdude 2020-09-03T12:41:30.083100Z

No problem, I'm learning something myself too

borkdude 2020-09-03T12:41:49.083300Z

This could be useful for preserving the old behavior in all other cases:

(def ^:dynamic *print-config* nil)

(def old-method (get-method print-method java.util.regex.Pattern))

(defmethod print-method java.util.regex.Pattern [v ^java.io.Writer w]
  (if *print-config*
    (.write w (pr-str (tagged-literal 'regex (.pattern v))))
    (old-method v w)))

(prn #"foo")
(binding [*print-config* true]
  (prn #"foo"))

👍 1
unbalanced 2020-09-03T22:20:35.084500Z

hey @borkdude. Babashaka rocks! Thanks!

unbalanced 2020-09-03T22:28:23.085900Z

might be a trap, but it feels like with a shockingly small amount of work this could be a monster alternative to Ansible. I tried it today but I don't know enough about executing remote ssh commands effectively, but I'm absolutely gonna check it out

unbalanced 2020-09-03T22:39:03.086300Z

although I suppose if I start going down that rabbithole I should probably just use clojure hmmm

unbalanced 2020-09-03T22:39:09.086500Z

but it's sooo tempting

2020-09-03T23:04:24.087700Z

@goomba i don't know what ansible does in detail, but perhaps there is some effort that addresses some of the functionality here? https://github.com/lread/clj-graal-docs/blob/master/doc/external-resources.md may be https://github.com/epiccastle/spire ?

🔥 1
unbalanced 2020-09-03T23:19:32.088700Z

wooo okay spire was probably what I was looking for. I was using babashka today to provision about a dozen machines

unbalanced 2020-09-03T23:20:21.089500Z

The tempting part from an enterprise perspective is I can sneak babashka even onto a pretty locked down redhat where they might not be crazy about JVM (for whatever reason)

unbalanced 2020-09-03T23:20:26.089700Z

Enterprise is so weird

unbalanced 2020-09-03T23:21:12.090Z

awesommmmeee resources!