Fork me on GitHub

Is there a way to use an older version of instead of the one included with babashka? I'm trying to call kibit with babashka. However, it seems kibit is using old api,


@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


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


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


@darong cool. there is a list of compatible libraries here: 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
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


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


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


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


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


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


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


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


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


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


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


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.


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


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?


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


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


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


Hmmmm it make sense :thinking_face:


/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


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


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


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


Oh, and btw, thanks for the help 😄


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


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


Wow it worked! Thanks so much @dpsutton 😄

👍 2

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


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


yes, it's the normal clojure *in*


of course 🙂


Ahh awesome! Thanks