Fork me on GitHub
#babashka
<
2021-06-02
>
darong15:06:08

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

borkdude15:06:00

@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

borkdude15:06:13

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

darong15:06:27

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

borkdude15:06:16

@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

👍 3
Jeff Evans19:06:01

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

Jeff Evans19:06:58

er, wait, sorry

Jeff Evans19:06:00

let me fix this

borkdude19:06:03

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

borkdude19:06:12

$ /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

Jeff Evans19:06:43

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

Jeff Evans19:06:47

sorry for the noise

borkdude19:06:14

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

Jeff Evans19:06:58

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

squiter19:06:29

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

borkdude19:06:21

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

borkdude19:06:56

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

squiter19:06:31

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

cfleming19:06:59

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

cfleming19:06:41

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

borkdude19:06:35

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

cfleming20:06:36

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.

borkdude20:06:57

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

squiter19:06:21

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?

dpsutton19:06:50

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

dpsutton19:06:52

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

dpsutton20:06:55

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

squiter20:06:26

Hmmmm it make sense :thinking_face:

dpsutton20:06:37

/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

dpsutton20:06:49

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

dpsutton20:06:53

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

squiter20:06:20

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

squiter20:06:26

Oh, and btw, thanks for the help 😄

dpsutton20:06:13

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

dpsutton20:06:39

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*)

squiter20:06:15

Wow it worked! Thanks so much @dpsutton 😄

👍 2
borkdude20:06:37

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

dpsutton20:06:02

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

borkdude20:06:12

yes, it's the normal clojure *in*

dpsutton20:06:17

of course 🙂

squiter20:06:19

Ahh awesome! Thanks