Fork me on GitHub
#babashka
<
2021-12-10
>
borkdude08:12:24

Watch a script and run tests while developing. Maybe something for #adventofcode? https://github.com/babashka/babashka/discussions/1102

h0bbit10:12:58

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?

borkdude10:12:47

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

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

h0bbit10:12:15

đź‘Ť will do

borkdude10:12:59

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

h0bbit10:12:31

@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.

borkdude10:12:26

Babashka 0.7.0 (2021-12-10) • Add compatibility with `clojure.spec.alpha`. See https://github.com/babashka/spec.alpha. • Add `to-array-2d`, `aclone`, `areduce` and `amap` (https://github.com/MrEbbinghaus) • Add `inst-ms` • Add `java.util.StringTokenizer` • clojure.core/read can read with `PushbackReader` that is not `LineNumberingPushbackReader` • Allow macroexpand on `for` and `doseq` (https://github.com/erdos) • 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 https://github.com/babashka/spec.alpha • 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
borkdude11:12:51

New blog post! Using `clojure.spec.alpha` with babashka: https://blog.michielborkent.nl/using-clojure-spec-alpha-with-babashka.html

awesome 2
Dig17:12:49

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

borkdude19:12:52

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 :).

Dig19:12:31

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

borkdude17:12:11

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.

Dig19:12:28

so i had to do

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

borkdude19:12:58

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
borkdude22:12:02

Today's Advent of Code puzzle was babashka-shaped again in terms of performance. https://twitter.com/borkdude/status/1469434518624948224