Skip to content

Instantly share code, notes, and snippets.

@ck
Forked from stuarthalloway/gist:2002582
Created May 31, 2012 22:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ck/2846903 to your computer and use it in GitHub Desktop.
Save ck/2846903 to your computer and use it in GitHub Desktop.
Datomic extent query
;; Datomic example code
;;
;; The extent of entity ?x is all datoms that are about ?x.
;; Drop this into your rules.
;;
;; Demonstrates
;;
;; 1. recursive query (extent calls itself)
;; 2. disjunction (different extent bodies are ORed)
;; 3. component attributes (e.g. your arm is a component, your brother isn't)
;; 4. navigating inbound and outbound references
'[[(extent ?x ?e ?a ?v) ;; match datoms where x is entity...
[?e ?a ?v]
[?x ?a ?v]
[(= ?e ?x)]]
[(extent ?x ?e ?a ?v) ;; ...or match datoms where x is value
[?e ?a ?v]
[?e ?a ?x]
[(= ?v ?x)]]
[(extent ?x ?e ?a ?v) ;; recurse where y is a component of x
(components ?x ?y)
(extent ?y ?e ?a ?v)]
[(components ?p ?c) ;; only follow component attributes
[?a :db/isComponent]
[?p ?a ?c]]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment