oh wow
Is there any way to extend fipp’s IEdn protocol in babashka, to control pretty printing?
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
But we might and then we could also expose more of it maybe
Just looking for a way to control pretty printing, or even printing
I’m trying to output a tagged literal for regexes
Can you give an example?
Of how you would do it on the JVM I mean
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.Let me see if that works on JVM
mm, doesn’t seem to do what I expected
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"
something like this?
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
I'm surprised bb supports this btw, I didn't expect it :)
OK, I just need to explicitly call fipp.ednize/edn
.
what about the above?
postwalk is certainly a viable workaround. ednize isn’t working as it refers to ThreadLocal.
What about the above print-method
?
Oh, sorry missed that. I thought I tried that before. Let me see
It does work on my machine's bb
OK, sorry for the noise. That does indeed work nicely 🙂
No problem, I'm learning something myself too
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"))
hey @borkdude. Babashaka rocks! Thanks!
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
although I suppose if I start going down that rabbithole I should probably just use clojure hmmm
but it's sooo tempting
@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 ?
wooo okay spire was probably what I was looking for. I was using babashka today to provision about a dozen machines
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)
Enterprise is so weird
awesommmmeee resources!