Fork me on GitHub

Does anyone happen to know why I can't seem to (import '[clojure.lang.Agent]) and resolve clojure.lang.Agent/pooledExecutor?


@rovanion Because that isn't mapped in babashka yet. Can you explain why you would need this?


So the reason why I want to do this is to implement future but using a pooled executor instead of the standard cached executor. The normal cached executor will spawn 8000 threads if 8000 futures are created at the same time. The pooled executor gives me the ability to limit the number of threads spawned to not choke the kernel. Now I used this technique once in normal Clojure when I built a filesystem benchmark, I wanted to benchmark the filesystem and not the kernels ability to juggle threads, but I can totally live with spawning a ton of threads for the application I'm writing now. So no need to map it in just for me.


@rovanion Could you write out the entire program? Because it would not only involve getting access to clojure.lang.Agent but also interop with executors


This is the code I used back then.


could you maybe post this as a file attachment - it bloats the channel a bit 🙂


But again, no need to do anything about it. I've realised that using the API is probably the wrong API for my current program. I probably want to use java.nio.2


@borkdude I have another suggestion for an addition; would like to use I'm happy to create a PR, but not sure about what you would suggest for the naming


Why not the clojure.core one?

user=> (require '[ :as data])
user=> (data/diff [1 2 3] [1 2 4])
[[nil nil 3] [nil nil 4] [1 2]]


is that a babashka repl?


no, a normal Clojure REPL


ok, so, my question was if adding it to babashka would be a good idea


yeah, I think adding clojure core thing to babashka is almost a no-brainer


I just haven't used this much, so I haven't added it


ok, and don't create a special name, just


take a look at the other namespaces for an example


e.g. babashka.impl/yaml, babashka.impl/xml etc


ok, thanks

Ahmed Hassan13:04:19

How can we use -IO in babashka script instead of command line? which public api functions are used for this?

b -IO '(filter #(< 1 (:foo %) 4) *input*)' < test.ednl


that would be something like

(ns foo
  (:require [clojure.edn :as edn]))

(doseq [x (filter #(< 1 (:foo 4) 4) (edn/read *in*))]
 (prn x))

👍 1

@ahmed1hsn It was slightly more complicated:

(ns foo
  (:require [clojure.edn :as edn]))

(defn read-edn []
  (take-while #(not (identical? ::EOF %))
              (repeatedly #(edn/read {:eof ::EOF} *in*))))

(doseq [x (filter #(< 1 (:foo %)) (read-edn))]
  (prn x))

✔️ 2
Ahmed Hassan13:04:55

what if *in* is file instead?


@ahmed1hsn *in* is from clojure.core:

user=> (doc *in*)
  A .Reader object representing standard input for read operations.

  Defaults to System/in, wrapped in a LineNumberingPushbackReader

👍 1

Thanks for the above snippet. Is there a way to automatically determine if *in* has anything on it without hanging the script? This probably isn't bb specific but just curious. I think it's good script etiquette to support args or stdin without unexpected hangs


@borkdude the example I provided, and you tweaked, seems to bug on print-table, is clojure.pprint/print-table not available in 0.0.88-2?


Great. Thanks!


@kah0ona I have just added this on master. Releasing now


aah ok 🙂 that explains it


That clj-together board is exciting. Particularly protocols as I'm guessing that would unlock usage of more 3rd party libs in bb. If there's a way to vote on issues, let me know. Otherwise I can drop a comment in an issue


commenting on issues is the only way to "vote" right now, I don't know of any other way

👍 1

@cldwalker I just discovered that you can sort issues at Github by thumbs up or thumbs down. So giving a thumbs up on an issue counts as voting


Good to know


Just wanted to say 👏 since babashka's nREPL completion works with my new Conjure completion integration! so cool!

🎉 3
🤯 3
❤️ 3

Is there a guide for adding library support to Babashka?


For example I'd like to add some bits from java.util.concurrent (Executors etc)


Also if you'd like to add stuff, please make an issue with a description of why you would like to add it. I'd like to screen it first, since adding things to babashka is not free in terms of binary size. If it's useful for general purpose scripting, or compatibility with existing libraries, that's often a good reason to add something


@borkdude Thanks, I missed that doc somehow. As for UPD: it's been rock solid since latest fixes metal Each ECS task deploys a tiny container as a sidecar which scrapes ECS metadata endpoint and sends container metrics via statsd protocol to our graphite server. I'm doing a write up about it - and from the looks of things I can open source it too. (3 charts we get from that)


Gotcha - I guess I got a bit excited since I almost see Babashka as the low-footprint Clojure I always wanted ;-)


awesome 🙂


so it's less about scripting, and more about building low-resource usage services which still deliver 80/90% of Clojure experience


but of course, that might go against your vision of the project


(in my ideal world, we just use native-image/graalvm for all our services but that's pretty challenging to pull off atm )


let's just see what it might add in terms of features and size. e.g. adding the postgres support was quite heavy (it added 3mb), but I think it will be very useful


Sure thing - I will have to set some time aside to dive into it first :thumbsup:


I don't know how much is it relevant for the discussion here, but yesterday I tried something. I took hsqldb and just for sake of curiosity I tried to compiled it with native-image and to my big surprised an 8.6MB binary was spit-out with runnable server-binary (Darwin). It seems from the documentation that hsqldb support in-process connection. I wonder if it's a possible candidate for embedding and eventual alternative to (native) sqlite.

👍 1

TIL about hsqldb - very cool. I've used H2 for this kind of stuff before


@ales.najmann If you would like to see hsqldb support in babashka, you can help by doing the research: create a graalvm cli that includes next.jdbc and hsqldb and make a POC like - it's basically because of that example that it was so easy to support postgres


Let's see how it goes. I'm not sure I'm skilled enough.


gotta start somewhere 🙂


haha, yeah that's right 🙂


a very minimal example would suffice, the main thing is to figure out the reflection config


@lukaszkorecki I now added a branch called executor that can execute this program:

(import '(java.util.concurrent Executors))

(defn run [nthreads niters]
  (let [a (atom 0)
        pool  (Executors/newFixedThreadPool nthreads)
        tasks (map (fn [_]
                     (fn []
                       (dotimes [_ niters]
                         (swap! a inc))))
                   (range nthreads))]
    (doseq [future (.invokeAll pool tasks)]
      (.get future))
    (.shutdown pool)
    (prn @a)))

(run 5 10) ;;=> 50
Binaries over here: Binary size seems to be ok, only like 380kb added or so

Ahmed Hassan19:04:25

now we can rely on java.util.concurrent instead of clojure.core.async. Does it include everything in this ns?

Ahmed Hassan19:04:31



ah, package. No I have only added three classes to begin with to make this snippet work. See the executor branch.

Ahmed Hassan19:04:23

Thanks, still a great start 🎉


Fantastic - I'll check out the diff to see what's involved :thumbsup:


Whenever I run something in bb, I get: setrlimit to increase file descriptor limit failed, errno 22 macOS


I made a simple Github Action to run clojure.test ☺️

🎉 4