This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-11-07
Channels
- # announcements (2)
- # babashka (38)
- # beginners (38)
- # calva (4)
- # cider (1)
- # clj-kondo (43)
- # clojure (50)
- # clojure-dev (39)
- # clojure-europe (4)
- # clojure-spec (4)
- # clojure-uk (2)
- # conjure (6)
- # core-async (5)
- # core-typed (3)
- # data-science (2)
- # datomic (6)
- # depstar (4)
- # emacs (1)
- # events (2)
- # fulcro (4)
- # jobs-discuss (4)
- # luminus (1)
- # off-topic (5)
- # re-frame (14)
- # shadow-cljs (8)
- # sql (8)
- # tools-deps (22)
I'm considering a .babashka/config.edn
or babashka.edn
where you can store things like :paths
, :classpath-cmd
(to calculate a classpath using e.g. clojure
or using a bb script itself), :pods
: pod specific settings, like where to download them.
If you have any input on this, here is the issue: https://github.com/borkdude/babashka/issues/473
any reason for a .babashka
folder and not just the equivalent of a .babashka_rc
file?
What would be the easiest way to craft something in bb that simply reads a number of edn forms from some file. I must be missing something obvious, but I invariably get off into weeds with needing to have a pushback-reader to use (clojure.edn/read). A bb (or clj) program that reads a file full of edn into memory should be hello world - so I must be missing somthing bigtime.
@hoppy so you have multiple values in one file, not like one value inside a vector right?
@hoppy In one-liners you can do this:
$ echo '{:a 1} {:a 2}' | bb -I -e "*input*"
({:a 1} {:a 2})
$ echo '{:a 1} {:a 2}' | bb -e "(take-while #(not= ::eof %) (repeatedly #(edn/read {:eof ::eof} *in*)))"
({:a 1} {:a 2})
oh right.
$ echo '{:a 1} {:a 2}' | bb -e "(let [reader (java.io.PushbackReader. (io/reader *in*))] (take-while #(not= ::eof %) (repeatedly #(edn/read {:eof ::eof} reader))))"
({:a 1} {:a 2})
it seems to be to be a missing bit in http://clojure.java.io frankly
I had an issue for that here, but then decided to close it as documentation could maybe fix that better. https://github.com/borkdude/babashka/issues/613
but maybe http://babashka.io which will replace the I/O flags (that some people find confusing) may work
it's a tricky spot. putting things in bb that wouldn't be in jvm may cause hardship for peeps that are unknowing using bb as a gateway drug.
we could also make one big babaskha.core or babashka.utils namespace where we accumulate functions that are missing from other core namespaces
dunno maybe I'm biased, but it seems like this should be a 1-liner in script space, at least if you would rather edn be the storage format than json or yaml. It's a little to bitey to get this loaded for my taste.
this is fun btw: https://grep.app/search?q=edn/read%20%7B%3Aeof%20
we could make babashka.edn as a counterpart to clojure.edn and add missing functions. similar for http://clojure.java.io / http://babashka.io. even if those small nss don't contain a lot of functions, they could be bundles in a babashka.misc library that bundles these little namespaces?
: push-back-reader
babashka.edn: edn-seq
;;=>
(bedn/edn-seq (bio/push-back-reader (io/reader file)))
we could make this easier. and create the pushback reader for you if it isn't one.
(bedn/edn-seq (io/reader file))
Then again, we could also call io/reader
on something if it isn't some reader:
(bedn/edn-seq file)
(defn edn-seq [reader-coercible]
(let [reader (cond (instance? java.io.PushbackReader reader-coercible)
reader-coercible
(instance? java.io.Reader reader-coercible)
(java.io.PushbackReader. reader-coercible)
:else (java.io.PushbackReader. (io/reader reader-coercible)))
sentinel (Object.)]
(take-while #(not (identical? sentinel %))
(repeatedly #(edn/read {:eof ::eof} reader)))))
I can see why a library would not offer this, e.g. line-seq
doesn't, since it depends on the usage when you want the reader to be closed. it's the lazy vs resources problem which is generally better solved with transducers@hoppy At least I added docs here how to translate i/o flags to scripts: https://github.com/borkdude/babashka/blob/master/doc/io-flags.md