babashka-sci-dev 2021-09-30

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.

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

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

oh you did :)

are you running into this with bb?

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.)

I'll look into it

@grzm 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?

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

Going to look into this tomorrow again.

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.

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

(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"]}

yeah good point