Fork me on GitHub
#babashka
<
2021-12-23
>
deas07:12:57

Hi! I'd like built uberscripts to include the shebang line and be executable. Am I missing something or do I have to come up with that bit myself? 😉

borkdude09:12:57

the shebang isn't added to remain cross-platform (Windows). how would you add an executable in the script?

👍 1
deas09:12:10

Windows? What's that? Got your point. Would still be nice to have something ready for the Unix minority.

borkdude09:12:01

Yes, I'm considering adding an option for this, or do it automatically, not sure yet

👍 1
pez09:12:34

Is it possible to use criterium in a babashka script? When I try include (:require [criterium.core :refer [quick-bench]]) in the ns form (or just require it) I get

Unable to resolve classname: java.lang.management.ManagementFactory

borkdude09:12:18

@pez I think criterium will be too low level for babashka, but you can use time :)

hugod14:12:58

I’m working on a new version of criterium, which puts all the management bean stuff into an impl namespace. I think it would be straightforward to provide a babashka version of the impl namespace, that just throws on the bits it can’t support. That would probably just support time measurement, but might still be useful.

🎉 2
pez09:12:17

I’ll use time then. 😃

pez09:12:40

And I don’t have java.util.BitSet, right?

borkdude09:12:56

are you doing Advent of Code?

pez09:12:33

Not really. I’m wasting time sieving primes. 😃

borkdude09:12:55

:-D We could add this class, not sure how much extra space it will take, I'll make a branch...

pez09:12:04

That’d be awesome. The rules of the competition says to only use one bit per prime for it to count as a solution “proper”. I have the sieve working using byte-array and it’s not crucial to get the “fully compliant” stamp on the solution. But it would be very nice, of course.

pez09:12:08

I have submitted some solutions in Clojure, but thought babashka should be represented as well. 😃

pez09:12:54

Even if it’s not a good choice for sieving primes. But anyway.

borkdude09:12:55

Added it to the bitset branch, should appear in 10 minutes or so in #babashka-circleci-builds - you can download it from there. I'll be afk for an hour or so.

pez09:12:11

Thanks!!!

borkdude10:12:24

It's there now. Let me know if this is useful or not for your purposes and how, before I will decide to merge it to master.

pez12:12:58

It almost works! 😃

pez12:12:58

Well, I’ve only found one thing that surprises me. In Clojure I can do this:

(-> bs .stream .toArray)
But in babashka that gives me:
No matching method toArray found taking 0 args for class java.util.stream.IntPipeline$Head

borkdude12:12:31

let me fix that

borkdude12:12:02

can you make a full example? I don't know what bs is

borkdude13:12:51

It's a little bit more complicated than I expected. I posted a question in the graalvm slack. https://graalvm.slack.com/archives/CN9KSFB40/p1640265505007500

borkdude13:12:14

$ ./bb -e '(-> (java.util.BitSet. 8) .stream .toArray)'
#object["[I" 0x498ef7c6 "[I@498ef7c6"]

borkdude14:12:29

I think I needed to concretely include the java.util.streams.IntStream class since the toArray is of a different type than the one in java.util.streams.BaseStream

borkdude14:12:41

so that solved it

pez11:12:20

You are a magician. It works like a charm.

pez12:12:15

Funny how slow it is compared to using a boolean-array and even a regular vector.

borkdude12:12:29

you mean in bb right? are you using lots of loops? interop in bb is slow because it uses reflection on every call, so I would expect it to be slower than when you go through clojure.core functions

borkdude12:12:44

this is some low hanging fruit which can be optimized

pez12:12:05

Yes, in bb. BitSets are slower than boolean arrays in Clojure as well, but not as radically.

pez12:12:47

Haven’t tried this particular algo setup with vectors in Clojure, but expecting it to be way slower than boolean-array and BitSet.

borkdude16:12:44

⚠ I need a few people who use the uberscript option for testing. I'm making a few changes to this which should improve loading namespaces which use pods, etc. But with every change there is a risk of breaking, so please respond in a thread if you want to test the change! đŸ§”