babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
2021-06-02T15:43:08.350800Z

Is there a way to use an older version of clojure.tools.cli instead of the one included with babashka? I'm trying to call kibit with babashka. However, it seems kibit is using old api, https://github.com/jonase/kibit/blob/master/kibit/project.clj

borkdude 2021-06-02T15:44:00.351600Z

@darong I think you can also evaluate tools.cli from source. in that case you should include it as a library in bb.edn and then use :reload to load it from source

borkdude 2021-06-02T15:45:13.352200Z

it would surprise me if kibit works with babashka though, I don't think babashka can run tools.reader or core.logic from source

2021-06-02T15:49:27.355200Z

@borkdude I'm new to babashka and playing around to see what works and what not. Thanks for the info. :reload is a nice trick, I'll definitely try it.

borkdude 2021-06-02T15:50:16.355800Z

@darong cool. there is a list of compatible libraries here: https://github.com/babashka/babashka/blob/master/doc/projects.md there might be more of course

πŸ‘ 1
2021-06-02T19:22:01.357500Z

I’m not sure if this is a regression or we’re just doing something wrong, but… the following fails in bb 0.4.4, but works fine in 0.4.3 create a file, test.clj, with these contents:

#!/usr/bin/env bb

(throw (ex-info "Some exception" {}))
add execute permission, then ./test.clj, it will fail with:
----- Error --------------------------------------------------------------------
Type:     clojure.lang.ExceptionInfo
Message:  Too many arguments to throw, throw expects a single Throwable instance
Location: /Users/jeff/./test.clj:3:1
Phase:    analysis

----- Context ------------------------------------------------------------------
1: #!/usr/bin/env bb
2:
3: (throw (ex-info "Some exception") {})
   ^--- Too many arguments to throw, throw expects a single Throwable instance

2021-06-02T19:22:58.358200Z

er, wait, sorry

2021-06-02T19:23:00.358500Z

let me fix this

borkdude 2021-06-02T19:23:03.358600Z

This is just some extra checking added to the throw special form, like in Clojure:

$ clj
Clojure 1.10.1
user=> (throw (ex-info "Some exception") {})
Syntax error compiling throw at (REPL:1:1).
Too many arguments to throw, throw expects a single Throwable instance

borkdude 2021-06-02T19:25:12.358900Z

$ /usr/local/bin/bb -e '(throw (ex-info "Some exception" {:a 1 :b 2}))'
----- Error --------------------------------------------------------------------
Type:     clojure.lang.ExceptionInfo
Message:  Some exception
Data:     {:a 1, :b 2}
Location: <expr>:1:1

----- Context ------------------------------------------------------------------
1: (throw (ex-info "Some exception" {:a 1 :b 2}))
   ^--- Some exception

2021-06-02T19:25:43.359500Z

yeah, I redact this for now. probably just a paste error

2021-06-02T19:25:47.359700Z

sorry for the noise

borkdude 2021-06-02T19:26:14.360300Z

no problem. you're correct that this used to work in bb 0.4.3 (it ignored the rest of the args), it just got a little stricter to conform with Clojure

2021-06-02T19:28:58.360700Z

nice, makes sense. yeah it turns out to be a bug in our threading macro

squiter 2021-06-02T19:32:29.362900Z

Hey folks, noob question here, I'm trying to parse some edn from the command line, and I don't know how to deal with the data-readers from those files... I'm trying something like this:

cat myfile.edn | bb -e "(set! *data-readers* {'my/data-reader identity}) (-> *input* :name)"
But I'm still receiving a data-reader error

borkdude 2021-06-02T19:33:21.363400Z

@squiter in this case it's probably better to just use edn/read-string with explicit data readers

borkdude 2021-06-02T19:33:56.363900Z

the *data-readers* var probably isn't hooked up to the edn reader, I think in clojure they are also separate

squiter 2021-06-02T19:34:31.364500Z

Hmmm got it... I'll try here, thanks for the tip!

cfleming 2021-06-02T19:37:59.365300Z

Is there a list of locations that the bb executable tends to be installed so I can try to default it for the user?

cfleming 2021-06-02T19:39:41.365800Z

Also, am I correct in thinking that bb includes tools.deps.alpha?

borkdude 2021-06-02T19:41:35.367100Z

@cfleming I think both brew and the bb install script (https://github.com/babashka/babashka/blob/master/install) install in /usr/local/bin/bb bb includes tools.deps.alpha in that it includes https://github.com/borkdude/deps.clj and that downloads the tools jar to resolve deps using the JVM I'll be back in half an hour, doing groceries.

squiter 2021-06-02T19:51:21.369600Z

Hmmm I'm still getting errors when uusing the edn/read-string... sorry to bother about that... this what I tried:

$ cat myfile.edn | bb -e "(edn/read-string {:readers (merge default-data-readers {'my/function identity})} *input*)"
----- Error --------------------------------------------------------------------
Type:     clojure.lang.EdnReader$ReaderException
Message:  java.lang.RuntimeException: No reader function for tag my/function
Location: 1:88
I'm trying to merge with the default-data-readers because I saw some data readers with this call:
$ bb -e "(clojure.pprint/pprint default-data-readers)"
{uuid #'clojure.uuid/default-uuid-reader,
 inst #'clojure.instant/read-instant-date}
Am I missing something?

dpsutton 2021-06-02T19:57:50.369900Z

bb -e "(clojure.edn/read-string {:readers (merge default-data-readers {'foo/bar (fn [y] [:hi y])})} \"#foo/bar [1 2 3]\")" returns [:hi [1 2 3]] for me

dpsutton 2021-06-02T19:59:52.370200Z

but i can confirm i'm getting an error when reading from input

dpsutton 2021-06-02T20:00:55.370800Z

but cat input.edn | bb -e "(println *input*)" also throws, so it seems like input is read as edn before the call to read-string

squiter 2021-06-02T20:01:26.371100Z

Hmmmm it make sense :thinking_face:

dpsutton 2021-06-02T20:02:37.371300Z

/tmp ❯❯❯ echo "(+ 1 1)" | bb -e "*input*"
(+ 1 1)
/tmp ❯❯❯ echo "(+ 1 1" | bb -e "*input*"
----- Error --------------------------------------------------------------------
Type:     clojure.lang.EdnReader$ReaderException
Message:  java.lang.RuntimeException: EOF while reading, starting at line 1
Location: 1:1

----- Stack trace --------------------------------------------------------------
 - <expr>:1:1

dpsutton 2021-06-02T20:02:49.371600Z

i wonder if there's a "raw-input" or some similar concept

dpsutton 2021-06-02T20:03:53.372100Z

or wrap input with \" \" so that it is a string of valid edn

squiter 2021-06-02T20:06:20.373100Z

Yeah, some kind of raw-input will do the trick... but I don't know if we have something like that... I'll take a look on the documentation

squiter 2021-06-02T20:08:26.373400Z

Oh, and btw, thanks for the help πŸ˜„

dpsutton 2021-06-02T20:10:13.373600Z

cat input.edn | bb -i -e "(clojure.edn/read-string {:readers (merge default-data-readers {'foo/bar (fn [y] [:hi y])})} (apply str *input*))"

dpsutton 2021-06-02T20:10:39.374200Z

use the -i and then *input* is a sequence of strings from input. so you can concat them all and off you go. (apply str *input*)

squiter 2021-06-02T20:13:15.374600Z

Wow it worked! Thanks so much @dpsutton πŸ˜„

πŸ‘ 1
cfleming 2021-06-02T20:19:36.374800Z

Ok, thanks! In that case I think I’ll try introspecting the available namespaces rather than downloading deps, and see how far I get with that approach.

borkdude 2021-06-02T20:52:57.375Z

Cool, if you need to know more, let me know

borkdude 2021-06-02T20:54:37.375500Z

@squiter @dpsutton actually in this case I would do:

$ echo '#my/function [1 2 3]' | bb -e "(edn/read {:readers (merge default-data-readers {'my/function identity})} *in*)"
[1 2 3]

dpsutton 2021-06-02T20:55:02.375900Z

aha, *in* is the "raw input" thing we were looking for?

borkdude 2021-06-02T20:55:12.376200Z

yes, it's the normal clojure *in*

dpsutton 2021-06-02T20:55:17.376500Z

of course πŸ™‚

squiter 2021-06-02T20:55:19.376600Z

Ahh awesome! Thanks