     (if (and throw-exception-if-no-complements-found
              (not (= true (get-in bolt (concat path [:phrasal])))))
       (exception message))))
+
+(defn lexemes-before-phrases [depth]
+  ;; takes depth as an argument; make phrases decreasingly likely as depth increases.
+  (let [result (> (rand-int (+ 1 depth)) 0)]
+    (log/trace (str "lexemes-before-phrases: depth=" depth " => " result))
+    result))
+
+(defn show-bolt [bolt path]
+  (if (not (empty? path))
+    (str (get-in bolt [:rule])
+         (let [rest-str (show-bolt (get-in bolt [:head]) (rest path))]
+           (if (not (nil? rest-str))
+             (str " -> " rest-str)))))) 

                  (add-complements-to-bolts [:head :comp])
                  (add-complements-to-bolts [:comp]))))))

(defn lexemes-before-phrases [depth]
  ;; takes depth as an argument; make phrases decreasingly likely as depth increases.
  (let [result (> (rand-int (+ 1 depth)) 0)]
    (log/trace (str "lexemes-before-phrases: depth=" depth " => " result))
    result))

;; TODO: add usage of rule-to-lexicon cache (rather than using lexicon directly)
(defn lightning-bolt [grammar lexicon spec depth index morph]
  "Returns a lazy-sequence of all possible trees given a spec, where
there is only one child for each parent, and that single child is the
head of its parent. generate (above) 'decorates' each returned lightning bolt
of this function with complements."
  (log/debug (str "lightning-bolt(depth=" depth ",cat=" (get-in spec [:synsem :cat]) ")"))
  (let [maxdepth 3 ;; maximum depth of a lightning bolt: H1 -> H2 -> H3 where H3 must be a lexeme, not a phrase.
        morph (if morph morph (fn [input] (get-in input [:rule] :default-morph-no-rule)))
        depth (if depth depth 0)        

            (log/debug (str "generate-all: cat: " (get-in spec [:synsem :cat])))
            (let [add-complements-to-bolts
                  (fn [bolts path]
                    (mapcat #(if (not (= :none (get-in % path :none)))
                               (add-complement % path :top grammar lexicon index morph 0)
                               [%])
                            bolts))]
              (-> (lightning-bolt (lazy-shuffle grammar)
                                     lexicon
