         (let [lexical ;; 1. generate list of all phrases where the head child of each parent is a lexeme.
               (mapcat (fn [parent]
                         (if (= false (get-in parent [:head :phrasal] false))
-                          (let [candidate-lexemes (filter #(not (nil? %)) (get-lex parent :head index spec))]
+                          (let [candidate-lexemes (filter #(not (nil? %)) (lazy-seq (get-lex parent :head index spec)))]
                             (filter #(not (nil? %))
                                     (over/overh parent (mapfn copy candidate-lexemes))))))
                       parents)

(ns babel.generate
  (:refer-clojure :exclude [get-in deref resolve find parents])
  (:require
   [babel.cache :refer [check-index get-head-phrases-of get-lex]]
   [babel.over :as over]
   [babel.stringutils :refer [show-as-tree]]
   #?(:clj [clojure.tools.logging :as log])

                                        )]))
                                        
;; during generation, will not decend deeper than this when creating a tree:
(def ^:const max-total-depth 3)

;; use map or pmap.
(def ^:const mapfn map)
