rules.cljs 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. (ns frontend.db.rules)
  2. (def rules
  3. '[[(parent ?p ?c)
  4. [?c :block/parent ?p]]
  5. [(parent ?p ?c)
  6. [?c :block/parent ?t]
  7. (parent ?p ?t)]
  8. [(namespace ?p ?c)
  9. [?c :block/namespace ?p]]
  10. [(namespace ?p ?c)
  11. [?c :block/namespace ?t]
  12. (namespace ?p ?t)]
  13. ;; from https://stackoverflow.com/questions/43784258/find-entities-whose-ref-to-many-attribute-contains-all-elements-of-input
  14. ;; Quote:
  15. ;; You're tackling the general problem of 'dynamic conjunction' in Datomic's Datalog.
  16. ;; Write a dynamic Datalog query which uses 2 negations and 1 disjunction or a recursive rule
  17. ;; Datalog has no direct way of expressing dynamic conjunction (logical AND / 'for all ...' / set intersection).
  18. ;; However, you can achieve it in pure Datalog by combining one disjunction
  19. ;; (logical OR / 'exists ...' / set union) and two negations, i.e
  20. ;; (For all ?g in ?Gs p(?e,?g)) <=> NOT(Exists ?g in ?Gs, such that NOT(p(?e, ?g)))
  21. ;; [(matches-all ?e ?a ?vs)
  22. ;; [(first ?vs) ?v0]
  23. ;; [?e ?a ?v0]
  24. ;; (not-join [?e ?vs]
  25. ;; [(identity ?vs) [?v ...]]
  26. ;; (not-join [?e ?v]
  27. ;; [?e ?a ?v]))]
  28. ])