Fork me on GitHub
#babashka
<
2020-09-13
>
coby18:09:26

Hey there, is it possible to get Babashka to pretty-print stuff using spit or similar?

#!/usr/bin/env bb

(binding [*print-pretty* true]
  (spit "something.edn" {:pretty {:printed :structure}}))

;; clojure.lang.ExceptionInfo: Could not resolve symbol: *print-pretty* [at /home/tamayo/projects/bread-cms/bin/bread, line 3, column 13]

borkdude18:09:35

Currently no, this is the first time I'm seeing this variable.

borkdude18:09:27

You can post an issue about this with some examples about what this does. I haven't used it in my 10 years of Clojure :)

borkdude18:09:54

Does this impact spit in normal Clojure?

coby18:09:01

I think so, checking...

dpsutton18:09:53

/tmp ❯❯❯ cd stuff
/t/stuff ❯❯❯ clj
Clojure 1.10.1
(binding [*print-pretty* true]
  (spit "something.edn" {:pretty {:printed :structure}}))
Syntax error compiling var at (REPL:1:1).
Unable to resolve var: *print-pretty* in this context
user=>

borkdude18:09:28

@dpsutton I think that var is coming from clojure.pprint

coby18:09:39

just realized that

coby18:09:28

but it doesn't solve my problem anyway, because it's already true

coby18:09:11

what I want is to display write EDN maps on multiple lines, which apparently it doesn't do. So I'll keep digging!

borkdude18:09:29

@ctamayo you can use (binding [*out* (io/writer your-file)] (pprint edn)) to write pretty to a file

coby18:09:16

hmm, that is printing to stdout for me, and writing an empty file

#!/usr/bin/env bb

(ns systems.bread.alpha.cli
  (:require
   [ :as io]
   [clojure.pprint :as pp]))

(defn write! [path content]
  (binding [*out* (io/writer path)]
    (pp/pprint content)))

(write! "something.edn" {:some :edn})

; $ bin/bread 
; {:some :edn}

borkdude18:09:14

hmm, let me try in normal clojure. could be a bug

coby18:09:35

yeah, working for me in clj

borkdude18:09:37

Seems to work both in clj and bb here. What's your bb version?

coby18:09:51

oh wow, it is embarrassingly old ... v0.0.86 😛

borkdude18:09:34

ok, try 0.2.0

coby18:09:24

working now, thanks! Sorry for the trouble!

Jakub Holý (HolyJak)22:09:14

Hi! Is it still so that the Cognitect aws api cannot be compiled to GraalVM native binary? Id like to make a bb aws lambda (quick cold start) but need to write to S3... Thanks!

borkdude22:09:21

@holyjak yes. it's a recurring topic :) you can read a recent discussion about this here: https://clojurians.slack.com/archives/CLX41ASCS/p1599750635174200

👍 3