babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
mozinator2 2020-12-10T08:58:54.165400Z

Anyone have a clue why I get error Could not resolve symbol: clojure.lang.PersistentList ? When doing

(def rop-dep '{:deps {rop/rop {:mvn/version "0.4.1"}}})
  (def cp (-> (sh "clojure" "-Spath" "-Sdeps" (str rop-dep)) :out s/trim))
  (add-classpath cp)
  (require '[rop.core :as rop])

borkdude 2020-12-10T09:00:42.166100Z

This is because not all classes are explicitly available for interop in babashka, they have to be manually added. Which library is this? (I'll be back in a bit)

🙏 1
mozinator2 2020-12-10T09:03:03.167Z

@borkdude the library I am trying to use is https://github.com/druids/rop which depends on https://github.com/funcool/cats where persistentList is referenced here: https://github.com/funcool/cats/blob/master/src/cats/builtin.cljc#L143

borkdude 2020-12-10T09:39:14.167500Z

@mozinator You're welcome to post an issue about this.

👍 1
mozinator2 2020-12-10T09:43:04.169200Z

Maybe the rop and cats library might be too heavyweight for babashka scripts anyway. I found this solution to error handling which seems to cover most of what I need https://adambard.com/blog/acceptable-error-handling-in-clojure/

mozinator2 2020-12-10T09:46:21.170200Z

@borkdude what are your criteria for adding libraries to the included libraries in babashka ?

mozinator2 2020-12-10T09:47:09.170500Z

Do you think https://github.com/clj-commons/camel-snake-kebab would be a good candidate ?

borkdude 2020-12-10T09:50:03.171200Z

camel-snake-kebab has been asked at least one time before. I'm willing to add it if more people ask for it in an issue.

borkdude 2020-12-10T09:50:29.171500Z

You can read the criteria here: https://github.com/borkdude/babashka#including-new-libraries-or-classes

borkdude 2020-12-10T09:51:08.172400Z

But since that lib can also be ran from source, there might not be a need to include it in babashka proper. This can be discussed in an issue though. So making an issue would be the first step.

👍 2
borkdude 2020-12-10T09:55:40.173200Z

I was trying out slingshot btw:

$ bb -e "(require '[slingshot.slingshot :as s]) (s/try+ (s/throw+ {:type ::foo}) (catch [:type ::foo] [] 1)))"
----- Error --------------------------------------------------------------------
Type:     java.lang.ClassNotFoundException
Message:  clojure.lang.RT
Location: <expr>:1:40

----- Context ------------------------------------------------------------------
1: (require '[slingshot.slingshot :as s]) (s/try+ (s/throw+ {:type ::foo}) (catch [:type ::foo] [] 1)))
                                          ^--- clojure.lang.RT
I'm not sure why this error appears, since I see no mention of clojure.lang.RT in the source code of slingshot

borkdude 2020-12-10T09:56:36.173400Z

I'll also make an issue for that.

borkdude 2020-12-10T09:58:01.173700Z

Ah, found the issue. Not sure why this is happening.

$ bb -e '(alength (into-array []))'
----- Error --------------------------------------------------------------------
Type:     java.lang.ClassNotFoundException
Message:  clojure.lang.RT
Location: <expr>:1:1

----- Context ------------------------------------------------------------------
1: (alength (into-array []))
   ^--- clojure.lang.RT
`

borkdude 2020-12-10T09:58:45.174Z

Maybe this uses reflection in Clojure?

(defn alength
  "Returns the length of the Java array. Works on arrays of all
  types."
  {:inline (fn [a] `(. clojure.lang.RT (alength ~a)))
   :added "1.0"}
  [array] (. clojure.lang.RT (alength array)))

borkdude 2020-12-10T09:59:39.174200Z

yap:

user=> (. clojure.lang.RT (alength (into-array [])))
Reflection warning, NO_SOURCE_PATH:1:1 - call to static method alength on clojure.lang.RT can't be resolved (argument types: unknown).
0

borkdude 2020-12-10T20:38:34.174700Z

https://www.thoughtworks.com/podcasts/future-clojure#trans > Obviously, you have ClojureScript compiling JavaScript, which was something that we started and led at the beginning, but is now led primarily outside of Cognitect by David Nolan and others. And then, a variety of other dialects and things that people are doing like the babashka for shell scripting in Clojure and those kinds of things.

10
borkdude 2020-12-10T22:37:46.175300Z

https://twitter.com/borkdude/status/1337164427095924737 <- the com.stuartsierra/dependency lib works with bb

🎉 4