This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-10-11
Channels
- # announcements (5)
- # babashka (43)
- # beginners (78)
- # calva (1)
- # cider (35)
- # clj-kondo (15)
- # clj-otel (3)
- # cljs-dev (2)
- # clojure (24)
- # clojure-denmark (1)
- # clojure-dev (9)
- # clojure-europe (43)
- # clojure-israel (1)
- # clojure-italy (1)
- # clojure-losangeles (3)
- # clojure-nl (1)
- # clojure-norway (54)
- # clojure-romania (1)
- # clojure-uk (2)
- # clojurescript (1)
- # core-async (25)
- # cursive (7)
- # datascript (6)
- # datomic (7)
- # docker (2)
- # emacs (2)
- # events (8)
- # exercism (2)
- # fulcro (2)
- # hyperfiddle (16)
- # lsp (46)
- # malli (10)
- # membrane (2)
- # music (6)
- # nbb (30)
- # off-topic (49)
- # polylith (4)
- # reagent (3)
- # releases (4)
- # shadow-cljs (5)
- # slack-help (1)
- # sql (2)
- # testing (2)
- # timbre (6)
- # tools-deps (29)
- # xtdb (36)
I'm curious why the core team added clojure.datafy/datafy when clojure.java.data/from-java was already there. One is a multimethod and the other a protocol but they seems to have the same purpose.
clojure.data/from-java
is not a thing in clojure -- link to what you're looking at?
probably this: https://github.com/clojure/java.data
java.data is about converting java objects following javabean patterns into Clojure data
datafy/nav allow lazy partial walking over arbitrary object graphs (which may not be fully realized in memory, like databases via jdbc or Datomic)
They do overlap in the sense of Java->Clojure but datafy/nav is much more general
Thanks Alex. From what I understand if not using nav it's the same thing. Actually you could even use the nav meta without datafy ?
Can I use the Navigable protocol with core map access function like get or :keyword ? Something like https://github.com/strojure/zmap. I need to navigate a geodatabase loaded from disk via interop. So I need to turn the java object into clojure maps lazily when accessing then. datafy/nav is cool for portal /rebl workflow, but I will rather use core fn to navigate the object graph.
that is not the goal of datafy/nav but there have been a variety of lazy map implementations written over time
Also bear in mind that clojure.java.data
is a separate Contrib library and is not part of core -- you need to add a separate dependency for it. And, as Alex says, it's intended for a completely different purpose.
I maintain java.data
these days and I'm also a heavy user of datafy
/ nav
-- they are very different 🙂
Can I use the Navigable protocol with core map access function like get or :keyword ? Something like https://github.com/strojure/zmap. I need to navigate a geodatabase loaded from disk via interop. So I need to turn the java object into clojure maps lazily when accessing then. datafy/nav is cool for portal /rebl workflow, but I will rather use core fn to navigate the object graph.
Is there a way to override an already-defined multimethod within a specific lexical scope in a manner similar to with-redefs
?
capture the old definition with get-method
, then define the new one, and when you leave the body, restore the old one?
(defmulti foo :id)
user=> (defmethod foo :dude [_] :dude)
#object[clojure.lang.MultiFn 0x1c12f3ee "clojure.lang.MultiFn@1c12f3ee"]
user=> (foo {:id :dude})
:dude
user=> (let [old-method (get-method foo :dude)] (.addMethod foo :dude (fn [_] :no-dude)) (prn (foo {:id :dude})) (.addMethod foo :dude old-method))
:no-dude
#object[clojure.lang.MultiFn 0x1c12f3ee "clojure.lang.MultiFn@1c12f3ee"]
user=> (foo {:id :dude})
:dude
Interesting. I do worry a bit about what might happen if this kind of dynamism is used in a multithreaded context. I think this https://github.com/camsaul/methodical may ultimately better support what I'm looking for, in part because it explicitly treats methods as immutable
well, you said, like with-redefs
, which is kind of a footgun, especially when multi-threading, so I kinda assumed you meant "for testing"
Right, i forgot about that https://stackoverflow.com/a/20139566 myself when asking the question!
I think using vars for both the dispatch fn and the method impls would be enough for my purposes before reaching for a library like methodical
.