This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-09-14
Channels
- # ai (3)
- # babashka (45)
- # beginners (81)
- # biff (26)
- # calva (10)
- # cider (5)
- # clj-kondo (55)
- # cljfx (6)
- # clojure (125)
- # clojure-berlin (1)
- # clojure-europe (37)
- # clojure-italy (7)
- # clojure-nl (3)
- # clojure-norway (79)
- # clojure-uk (1)
- # clojurescript (63)
- # clojutre (1)
- # conjure (5)
- # cursive (37)
- # data-science (1)
- # datalevin (4)
- # datomic (28)
- # eastwood (6)
- # fulcro (26)
- # graphql (20)
- # honeysql (6)
- # humbleui (4)
- # jobs-discuss (5)
- # kaocha (1)
- # leiningen (8)
- # missionary (5)
- # nbb (4)
- # observability (3)
- # off-topic (7)
- # pathom (8)
- # podcasts-discuss (1)
- # rewrite-clj (18)
- # ring (6)
- # sci (23)
- # scittle (9)
- # shadow-cljs (49)
- # squint (10)
- # testing (11)
- # xtdb (17)
After using Datomic for the last couple of months I had an idea to implement https://en.wikipedia.org/wiki/Greenspun%27s_tenth_rule in the database. I'm wondering how bad an idea is modeling https://en.wikipedia.org/wiki/Hash_consing lists with a schema like this?
[{:db/ident :pair/car
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}
{:db/ident :pair/cdr
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}
{:db/ident :pair/car+cdr
:db/valueType :db.type/tuple
:db/tupleAttrs [:pair/car :pair/cdr]
:db/cardinality :db.cardinality/one
:db/unique :db.unique/identity}]
in the docs for datomic.api/entity
it says an entity implements clojure.lang.Associative
, but when I do (assoc my-entity :foo 1)
I get an exception
1. Unhandled java.lang.AbstractMethodError
Receiver class datomic.query.EntityMap does not define or inherit
an implementation of the resolved method 'abstract
clojure.lang.Associative assoc(java.lang.Object, java.lang.Object)'
of interface clojure.lang.Associative.
also
(instance? clojure.lang.Associative my-entity) ;; => true
looking at (datafy datomic.query.EntityMap)
I see clojure.lang.Associative
under :bases
but no assoc
under members
. Am I not understanding what “implements” means?
If you are looking to assoc on Datomic entities, here's some code that lets your wrap a Datomic entity - keeping its semantics, while also accepting assoc. I'm not sure it's a good idea tho. https://gist.github.com/magnars/f2fb046904e7c1ea57dca7058266da1d
neat! still curious why it says on the tin that entity implements clojure.lang.Associative while it seems it really does not.
In case you're wondering about the clojurescript part of the code, that's for using datascript in the browser. It's been in use for several years, so it's pretty battle tested code.
You don't have to implement every method to “implement” (in Java instanceof sense) an interface
TIL, thanks :thumbsup:
E.g. you can reify/gen-class/deftype/defrecord in clojure and only partially implement an interface, and clojure will happily generate the class bytecode and the jvm will accept it and just runtime error if you try to call a missing method
you can walk your entity and run (into {})
at each level where appropriate, or just run it at top level without the walk, then you get your normal map instead of a datomic ent (maybe sometimes you want this, but you also get this with a pull, which is probably better than walking an entity)
is this transaction a no-op or will the history include this?
[[:db/retract 123 :foo/bar 1]
[:db/add 123 :foo/bar 1]]
I could check myself, but haven’t learned how to yetthat’s disappointing. thanks though 🙂
Disappointing in the sense that I need to apply myself.