Fork me on GitHub
#babashka-sci-dev2021-09-30
>
grzm19:09:31

Moved https://github.com/borkdude/sci/issues/378 an inch (or maybe just a centimeter!) forward, confirming that the priority order of searching for a protocol method implementation is wrong.

grzm19:09:01

It's finding the exend-protocol implementation before the metadata implementation.

borkdude19:09:53

ah thank you. can you comment in the issue as well?\

borkdude19:09:01

oh you did :)

borkdude19:09:48

are you running into this with bb?

grzm20:09:12

I was hoping to start leveraging extend-with-metadata for data. We’re using a Stuart Sierra component-like system to express resource dependencies, and we don’t really need records for the data the resources: maps would be fine . (But that’s what we’re doing now as that’s what we to do given the current limitation.)

borkdude20:09:48

I'll look into it

borkdude20:09:40

@U0EHU1800 So the issue is that the metadata is prioritized while it shouldn't right?

(foo (with-meta (->Dude) {`foo (fn [this] :meta)}))
This should not return :meta if the record implements the protocol already right?

borkdude20:09:11

I see that's a different case that doesn't work. Here SCI incorrectly prioritizes the metadata it seems

borkdude21:09:00

Going to look into this tomorrow again.

grzm21:09:16

I think what you're seeing above is that the metadata about the record implementing the protocol got replaced by the with-meta. If you use vary-meta to just update the existing metadata, you'll see that it prioritizes the direct implementation over the meta-data implementation.

grzm21:09:25

(I got bit by the same thing when I was testing)

grzm21:09:51

(def fooer-vary-meta (vary-meta (->Fooer) assoc `foo (fn [_] {:impl :with-meta})))
(foo fooer-vary-meta);; => {:impl :defrecord}
(meta fooer-vary-meta)
;; => {:sci.impl/record true,
;;     :type user/Fooer,
;;     user/foo
;;     #object[sci.impl.fns$fun$arity_1__1208 0x27dc294a "sci.impl.fns$fun$arity_1__1208@27dc294a"]}

(def fooer-with-meta (with-meta (->Fooer) {`foo (fn [_] {:impl :with-meta})}))
(foo fooer-with-meta);; => {:impl :extend-protocol}
(meta fooer-with-meta)
;; => {user/foo
;;     #object[sci.impl.fns$fun$arity_1__1208 0x437834e1 "sci.impl.fns$fun$arity_1__1208@437834e1"]}

borkdude21:09:02

yeah good point