Last Updated: February 25, 2016
·
968
· rodnaph

Clojure/Datomic Reader Macro Gotcha

Datomic schema transactions are quite verbose, so I created a little helper for myself...

(defn attr [ident type]
  {:db/id #db/id [:db.part/db]
   :db/ident ident
   :db/valueType type
   :db/cardinality :db.cardinality/one
   :db.install/_attribute :db.part/db})

Spot the mistake? No, well it took me some debugging to find too. Reader macros are expanded (as the name suggests) at compile time like normal macros. So the #db/id reader macro for creating a new temporary ID is only ever executed once, giving all my attributes the same ID.

Doh! So I need to change it to (only change shown)...

:db/id (d/tempid :db.part/db)

So, just something to remind yourself of when using them.