Skip to content

Instantly share code, notes, and snippets.

@comnik
Created July 12, 2018 16:56
Show Gist options
  • Save comnik/c6e917901ceb16ec90d87255835bc533 to your computer and use it in GitHub Desktop.
Save comnik/c6e917901ceb16ec90d87255835bc533 to your computer and use it in GitHub Desktop.
;; LWW Register
;; https://speakerdeck.com/ept/data-structures-as-queries-expressing-crdts-using-datalog?slide=15
(def schema
{:assign/time {:db/valueType :Number}
:assign/key {:db/valueType :Number}
:assign/value {:db/valueType :Number}})
(def rules
'[[(older ?t1 ?key)
[?op :assign/key ?key] [?op :assign/time ?t1]
[?op2 :assign/key ?key] [?op2 :assign/time ?t2]
[(< ?t1 ?t2)]]
[(lww ?key ?val)
[?op :assign/time ?t]
[?op :assign/key ?key]
[?op :assign/value ?val]
(not [(older ?t ?key)])]])
;; possible ergonomics improvement
(def rules
'[[(older ?t1 ?key)
#:assign{:key ?key :time ?t1}
#:assign{:key ?key :time ?t2}
[(< ?t1 ?t2)]]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment