                    ["Medusa" 1]
                    ["Cyclops" 1]
                    ["Chimera" 1] ]]
-  (q '[ :find (sum ?heads) (min ?heads) (max ?heads) (count ?heads)
-                       :with ?monster
-                       :in   [[?monster ?heads]] ]
-                    monsters))
+  (q '[:find (sum ?heads) (min ?heads) (max ?heads) (count ?heads)
+       :with ?monster
+       :in   [[?monster ?heads]] ]
+    monsters))
 
 #_(q '[ :find ?color (max ?amount ?x) (min ?amount ?x)
       :in   [[?color ?x]] ?amount ]

                [:db/add 3 :age  22]]))
   ["Ivan" "Petr"])

#_(q '[:find ?e
     :with ?e2
     :where [?e :name ?n]
            [?e2 :name ?n2]]
  (-> (d/empty-db)


(defn -collect
  ([context symbols]
    (let [rels (:rels context)
          data (-collect [(make-array (count symbols))] rels symbols)]
      (set (map vec data))))
  ([acc rels symbols]
    (if-let [rel (first rels)]
      (let [keep-attrs (select-keys (:attrs rel) symbols)]
        (if (empty? keep-attrs)
          (recur acc (next rels) symbols)
          (let [copy-map (to-array (map #(get keep-attrs %) symbols))
                len      (count symbols)]
            (recur (for [t1 acc
                         t2 (:tuples rel)]
                     (let [res (aclone t1)]
                       (dotimes [i len]
                         (when-let [idx (aget copy-map i)]
                           (aset res i (aget t2 idx))))
                       res))
                   (next rels)
                   symbols))))
      acc)))

(defn find-attrs [q]
