               (let [filtered
                     (->>
                      (:grammar model)
-                     (map (fn [rule]
-                            (let [result (unify rule spec)]
-                              (cond (= :fail result)
-                                    (log/debug (str "rule:" (:rule rule)
-                                                    " => "
-                                                    "FAIL between:"
-                                                    (:rule rule)
-                                                    " and: "
-                                                    (strip-refs spec)
-                                                    "; fail path:"
-                                                    (dag_unify.core/fail-path
-                                                     rule
-                                                     spec)))
-                                    true
-                                    (log/debug (str "rule:" (:rule rule)
-                                                    " OK for spec:"
-                                                    (dag_unify.core/strip-refs
-                                                     spec))))
-                              result)))
+                     (map #(unify % spec))
                      (filter #(not (= :fail %)))
                      (shufflefn))]
                 (if (empty? filtered)

      (do (log/trace (str "no compiled bolts found for: " search-for-key))
          (lazy-seq (lightning-bolts model spec 0 depth))))))

(defn lightning-bolts
  "Return every possible bolt for the given model and spec. Start at the given depth and
   keep generating until the given max-depth is reached."
  [model spec depth max-depth & [use-candidate-parents]]
  ;; 'lightning bolts' look like:
  ;; 
  ;; 
  ;;   H        H    H
  ;;    \      /      \
  ;;     H    H        H        ...
  ;;    /      \        \
  ;;   H        ..       ..
  ;;    \
  ;;     ..
  ;; 
  ;; Each bolt is a tree with only one child per parent: the head child.
  ;; Each head child may be a leaf or
  ;; otherwise has a child with the same two options (leaf or a head child),
  ;; up to the maximum depth.
  (log/debug (str "lightning-bolts: depth="
                  depth "; spec=" (dag_unify.core/strip-refs spec)))
  (if (and (< depth max-depth)

(def ^:const shufflefn
  (fn [x]
    ;; deterministic generation:
    (cond
      false
      (take 1 x)
      
      false
      (shuffle (take 10 x))

      false
      (if (not (empty? x))
        (cons (rand-nth x) x)
        x)

      true
      ;; nondeterministic generation
      (lazy-seq (shuffle x)))))

(declare add-comp-to-bolts)
(declare add-comps-to-bolt)
