This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-03-25
Channels
- # announcements (8)
- # aws (50)
- # aws-lambda (6)
- # babashka (25)
- # beginners (119)
- # bristol-clojurians (5)
- # calva (25)
- # chlorine-clover (23)
- # cider (6)
- # cljs-dev (125)
- # clojure (63)
- # clojure-austin (1)
- # clojure-belgium (1)
- # clojure-dev (48)
- # clojure-europe (11)
- # clojure-italy (2)
- # clojure-nl (5)
- # clojure-spec (3)
- # clojure-uk (66)
- # clojurescript (14)
- # core-logic (5)
- # datomic (13)
- # emacs (10)
- # events (2)
- # fulcro (37)
- # graalvm (11)
- # hoplon (95)
- # jobs-discuss (9)
- # juxt (11)
- # kaocha (16)
- # meander (13)
- # off-topic (24)
- # pedestal (4)
- # re-frame (36)
- # reagent (10)
- # reitit (15)
- # ring-swagger (5)
- # shadow-cljs (23)
- # spacemacs (2)
- # sql (13)
- # tools-deps (32)
- # xtdb (11)
What is the idiomatic way to read an edn file in bb? First attempt: (edn/read-string (slurp (io/file "deps.edn")))
@pithyless That's how I usually do it. I guess you can also do:
$ bb '(edn/read (.PushbackReader. (io/reader (io/file "/tmp/foo.edn"))))'
{:a 1}
which is more characters. There's nothing specific to bb about reading EDN files this way. However, you can also use an input flag to read EDN from stdin:
$ cat /tmp/foo.edn | bb -I '*input*'
({:a 1})
That is mostly for one-liners, for scripts I would do it with one of the former ways
with no input flags, the input is bound to EDN from stdin. With -I
this changes to a lazy seq of EDN values from stdin.
bb '(:a *input*)' <<< '{:a 1}'
1
I found this surprisingly aesthetically pleasing. I also noticed that you don't crash on "invalid EDN-format input" on stdin if I don't read *input*
. Nice!That's amazing! If you care for it, I'd love to read the code where you (I assume) prevent that first pipeline part from producing more than the 3 elements that are requested for the second pipeline part.
@teodorlu this code is mostly in babashka.main and it uses the PIPE signal to prevent reading any further
btw, it doesn't work on Windows where the PIPE signal isn't available with GraalVM native-image
@borkdude does sun.misc.Signal
's presence in babashka mean we can handle signals in our scripts?
I have a bb script that ends up running clojure -A:repl ...
and I've found if I hit ctrl-c in the repl, the bb script exits and the child java process spins out of control
was thinking of trapping ctrl-c, cleanly exiting the java process, and then exit my bb script
I've never trapped a signal in java or clojure, just hoping that I have an avenue to pursue