Fork me on GitHub
#babashka
<
2021-01-20
>
seminioni08:01:55

thank you @borkdude im newcomer in clojure(script) world, so hope will find a lot of interesting here 🙂

henryw37411:01:54

Hi all. Is it possible to extend protocols to clojure maps and functions with bb? I'm having a look at getting tick library working and it does

(extend-protocol Foo
  clojure.lang.Fn
  ...
in a few places

borkdude11:01:26

@henryw374 Do you have an isolated small example for me?

borkdude11:01:24

@henryw374 This works in bb:

(defprotocol Foo
  (foo [_]))

(extend-protocol Foo
  Number
  (foo [x] (prn :x x)))

(foo 1)

borkdude11:01:41

But some classes aren't available (yet) which can be potentially fixed in the next version

henryw37411:01:58

ok so I found clojure.lang.IFn is there, so tick could use that instead of clojure.lang.Fn I think, but for maps,

#!/usr/bin/env bb

(defprotocol Foo
  (bar [_] ))

(extend-protocol Foo 
  clojure.lang.IFn
  (bar [f] (f))
  clojure.lang.APersistentMap
  (bar [x] x))

(bar (fn [] "yay!"))
(bar {})

henryw37411:01:31

so I guess clojure.lang.APersistentMap would need adding, unless there's an alternative

borkdude11:01:47

a map is also an IFn, so not sure which one would take priority there

henryw37411:01:02

interesting!

henryw37411:01:29

yeah good point, I'll dig in. thanks

borkdude11:01:01

there is IPersistentMap in bb btw

borkdude11:01:29

@henryw374 This works:

#!/usr/bin/env bb

(defprotocol Foo
  (bar [_] ))

(extend-protocol Foo
  clojure.lang.IPersistentMap
  (bar [x] [:map x])
  clojure.lang.IFn
  (bar [f] [:fn (f)]))

(prefer-method bar clojure.lang.IPersistentMap clojure.lang.IFn)

(prn (bar (fn [] "yay!")))

(prn (bar {}))
but it leaks the implementation detail that bb uses multi-methods to implement protocols ;P

henryw37411:01:43

cool. I'm fairly sure I can get tick working then

borkdude11:01:25

if we added clojure.lang.Fn to bb then you could leave out the impl detail

henryw37411:01:22

hmm, that'd be nicer for sure

borkdude11:01:28

ok, I'll include that in 0.2.7, let me know when you want to release tick for bb, so I can push a new release

henryw37411:01:52

great thanks. no great hurry really 🙂

borkdude20:01:32

Babashka 0.2.7 released We are re-introducing Alpine images along with the main Ubuntu image (thanks @rahul080327) https://hub.docker.com/repository/registry-1.docker.io/babashka/babashka/tags?page=1&amp;ordering=last_updated And various other small improvements (like the one discussed earlier today).

🎉 6
frankitox23:01:31

Nice, works fine on my Pi 🙂 (And I'm using the 64 bit version of the OS)

👍 3
isak17:01:32

@U3UFFB420 the default rasberry pi OS, or something else like the post?

frankitox17:01:29

It's the Raspberry Pi OS, but a 64 bit beta, I downloaded based on what I read https://www.raspberrypi.org/forums/viewtopic.php?t=275370

3