 (defn comp-path-to-complements
   "return a lazy sequence of bolts for all possible complements that can be added to the end of the _path_ within _bolt_."
   [bolt path model depth max-depth]
-  (log/info (str "comp-path-to-complements:" depth "/" max-depth ":" ((:morph-ps model) bolt) "@" path))
+  (log/debug (str "comp-path-to-complements:" depth "/" max-depth ":" ((:morph-ps model) bolt) "@" path))
   (let [spec (get-in bolt path)
         lexemes (shufflefn (get-lexemes model spec))
         bolts-at (if (< depth max-depth)
-                   (generate-all
-                    (get-in bolt path)
-                    model
-                    (+ 1 depth) max-depth))
+                           ;;                                   (generate-all (get-in bolt path) model
+                           (lightning-bolts model (get-in bolt path)
+                                            (+ 1 depth) max-depth))
         lexemes-before-phrases
         (lexemes-before-phrases depth max-depth)]
     (if lexemes-before-phrases

            (assoc
             (comp-paths-to-complements bolt (find-comp-paths bolt) model depth max-depth)
             [] [bolt])))
     (mapcat (fn [each-bolt-and-comps] ;; for each such map in each bolt, find all possible combinations of complements, taking one complement per path.
               ;; the result is a trellis for each bolt, and a path through this trellis is one complement for each complement position.
               (map (fn [each-path-through-trellis]
                      (zipmap (keys each-bolt-and-comps)
                              each-path-through-trellis))
                    (apply combo/cartesian-product (vals each-bolt-and-comps)))))
     (map (fn [bolt-and-comps]
            (apply unify
                   (let [bolt (get bolt-and-comps [])
                         paths-and-comps (dissoc bolt-and-comps [])
                         paths (keys paths-and-comps)]
                     (cons bolt
                           (map (fn [path]
                                  (let [result (assoc-in bolt path (get paths-and-comps path))]
                                    (if (= true truncate)
                                      (dissoc-paths result [path])
                                      result)))
                                paths))))))
     (map (fn [expression]
            (do-defaults expression model)))
     (filter not-fail?)
     (map (fn [final]
            (log/trace (str "final: " ((:morph-ps model) final)))
            final)))))

(defn generate
  "Return one (by default) or _n_ (using :take _n_) expressions matching spec _spec_ given the model _model_."

(def ^:const mapfn map)

;; deterministic generation:
;;(def ^:const shufflefn (fn [x] x))

;; nondeterministic generation
(def ^:const shufflefn shuffle)

(def ^:const randomize-lexemes-before-phrases
  false)
