Fork me on GitHub
#babashka
<
2022-03-12
>
borkdude11:03:28

Turns out that zprint is (mostly) compatible with babashka :) https://github.com/kkinnear/zprint/pull/228

šŸŽ‰ 3
bananadance 1
borkdude12:03:23

Also the expectations library (need to define clojure-version only for the tests)

$ BABASHKA_PRELOADS="(intern 'clojure.core 'clojure-version (fn []))" bb test:bb

Testing expectations.clojure.test-test

Running inline tests

Ran 22 tests containing 82 assertions.
0 failures, 0 errors.

šŸŽ‰ 1
borkdude12:03:54

Adding clojure-version now for next release

borkdude13:03:53

And hugsql.core sqlvec fns also works in babashka :) (from the next release on)

(deftest sqlvec-test
  (is (= ["select name, specialty from characters\nwhere id in (?,?)" 1 2]
         (characters-by-ids-specify-cols-sqlvec {:ids [1 2], :cols ["name" "specialty"]}))))

šŸ‘ 2
šŸŽ‰ 2
borkdude13:03:29

$ bb -e '(clojure-version)'
"1.11.0-beta1-SCI"
$ bb -e '*clojure-version*'
{:major 1, :minor 11, :incremental 0, :qualifier "beta1-SCI"}

borkdude17:03:47

I'm very to close to making specter run from source now...

Ran 135 tests containing 465 assertions.
0 failures, 6 errors.
{:test 135, :pass 459, :fail 0, :error 6, :type :summary}
Just a nasty reflection issue in a combination of clojure.lang.IReduce and clojure.lang.IReduceInit + reify

šŸ¤Æ 1
wilkerlucio17:03:12

thanks for keep making babashka more and more awesome šŸ™‚

Sam Ritchie23:03:48

Deftype is off the table for babashka, right? Just double checking

Bob B03:03:51

as I understand it, deftype dynamically defines a new Java class, and GraalVM doesn't allow for the creation (as in definition) of classes at runtime, so they're incompatible

Sam Ritchie05:03:46

interesting, I have deftypes all over #sicmutils but Iā€™d be happy to compile classes instead, or use some form graal, js and jvm would be happy with. Is there an alternative?

borkdude07:03:30

Deftype isn't implemented since people usually use it for low level stuff and implement more than 1 java interfaces in them which is hard to support since you need to know all combinations at babashka compile time. Defrecord is the closest alternative

borkdude08:03:46

We could add support for a subset of deftype usages, but it would have the same restriction as defrecord: only 1 Java interface may be implemented at a time

teodorlu10:03:11

Wait, I thought #sicmutils already worked on #sci? Have I missed something?

borkdude10:03:45

It works with SCI bindings, but this is a different usage than running it entirely from source in SCI

borkdude10:03:45

You can make almost any library work by plugging in the right SCI bindings

teodorlu10:03:48

Ah, ok. So the deftypes don't actually run in sci. Thanks for explaining šŸ‘

borkdude10:03:23

yes. we could support deftype for some cases, similar to how we support defrecord but usually people implement all kinds of interfaces on those things that make it very hard to pull it off correctly

šŸ‘ 1
Sam Ritchie16:03:38

In sicmutils the usual pattern is to make something feel like a vector, but override IFn and add more SICM-specific protocols

borkdude16:03:39

that might be supported

Sam Ritchie16:03:46

Okay, I'll make a task to get the full list of deftypes together and we'll see what we can do

borkdude16:03:21

$ bb -e '(def x (reify clojure.lang.IFn (invoke [_] :dude))) (x)'
:dude

borkdude16:03:41

on records it doesn't work currently I think

Sam Ritchie14:03:55

here is the sort of thing @U04V15CAJ that we are dealing with. most look very similar to this

Sam Ritchie14:03:41

I also wanted to ask if you have a suggested way that I could incrementally make this conversion; for example, make a, or something and start growing up toward sicmutils.env

borkdude14:03:27

That sort of deftype is similar to the one from instaparse: it implements a bunch of stuff to make it a custom data structure with lots of interfaces which isn't possible in bb.

borkdude14:03:05

You can use either reader conditionals, :bb or the .bb extension to override code for bb

borkdude14:03:28

bb accepts both :clj and :bb reader conditionals, if you are using :bb you must place it before the :clj one

Sam Ritchie14:03:53

Is the answer perhaps to write the class in Java?

borkdude14:03:02

Babashka cannot execute Java classes

borkdude14:03:38

The answer, if you want to make your code bb compatible, is probably to use reader conditionals and support a subset

borkdude14:03:08

or you could write a pod that you can load from babashka, that's also an option. I don't know enough about SICMutils API to say if that's a good fit

borkdude14:03:23

Pods's arguments are serialized as json, edn or transit.

borkdude14:03:40

If you want to serialize functions, that's usually a problem

borkdude14:03:55

So maybe the subset approach could work. In your Structure example, this would mean: implement Structure as a record and remove the non-protocol implementations except Object using :bb reader conditionals