Fork me on GitHub

Watch a script and run tests while developing. Maybe something for #adventofcode?


In the babashka script that I'm writing, I want to optionally process input from stdin. That is, both git diff a..b --name-only | components as well as components a b are valid invocations of the command. My problem is that if I use (slurp *in*) to read the input, then the components a b version of the command hangs forever waiting for input on the in pushbackreader. What's the right way to deal with this?


@h0bbit Not really sure how reliable this is, but you can try .available:

$ bb -e '(.available System/in)'
$ echo 'hello' | bb -e '(.available System/in)'


đź‘Ť will do


@h0bbit usually command line applications do this with an explicit arg like --stdin or just -


@borkdude yeah, that makes sense. I think I'll put in an explicit argument --stdin. I don't think - is an acceptable input for cli-opts.


Babashka 0.7.0 (2021-12-10) • Add compatibility with `clojure.spec.alpha`. See • Add `to-array-2d`, `aclone`, `areduce` and `amap` ( • Add `inst-ms` • Add `java.util.StringTokenizer` • clojure.core/read can read with `PushbackReader` that is not `LineNumberingPushbackReader` • Allow macroexpand on `for` and `doseq` ( • Add `clojure.instant/read-instant-date` • Add `StackTraceElement->vec` • Add `memfn` • Implement Java field access (for `clojure.spec.alpha`) • Warn on requiring `clojure.spec.alpha`, suggesting to use • Warn on requiring `clojure.core.specs.alpha`, suggesting to explicitly add it to deps • Deprecate `$` in babashka.process (still available, but no longer recommended)

🚀 7
❤️ 2
đź‘Ź 1
🙌 1

New blog post! Using `clojure.spec.alpha` with babashka:

awesome 2

what is the recommended way instead of deprecated $ macro? just process?


The reason for deprecation was that threading didn't work properly and I don't think the fancy syntax really added any value. But if enough people convince me otherwise and want to fix an issue with it, I may un-deprecate it in the future :).


i've ran into some issues with it too, like lsp formatter will try to add a space

($ script param=~p1) -formater-> ($ script param= ~p1)
and that breaks that script


After evaluation param= and ~p1 are two different token anyway, so this isn't something that can be fixed in the macro either. But I undeprecated it now again.


so i had to do

($ script ~(str "param=" p1))


A spec demo using the core specs.

$ neil add dep :lib babashka/spec.alpha :latest-sha true :deps-file bb.edn
$ neil add dep :lib org.clojure/core.specs.alpha :deps-file bb.edn
$ bb -e "(require '[clojure.spec.alpha :as s] '[clojure.core.specs.alpha :as cs]) 
(s/conform ::cs/defn-args '[foo [x] x])"

{:fn-name foo, :fn-tail [:arity-1 {:params {:params [[:local-symbol x]]}, :body [:body [x]]}]}

$ bb -e "(require '[clojure.spec.alpha :as s] '[clojure.core.specs.alpha :as cs] '[clojure.test.check.generators :as gen]) (gen/sample (s/gen ::cs/defn-args))"
((_ ([] {} nil)) (j {} [] ()) (R [] {} [false] nil)
I guess y'all know how spec works, but I'm just excited that pretty much all of it works in bb now ;)

🎉 3

Today's Advent of Code puzzle was babashka-shaped again in terms of performance.