当然可以,
(defn is_prime [num]
(letfn [(helper [i]
(cond
(> i (Math/sqrt num)) true
(= 0 (rem num i)) false
:else (recur (inc i))))
(helper 2)))
;返回一个惰性序列,其每个后续元素都经过谓词过滤
(defn filter-lazy-seq [predicate sequence]
(cond (= sequence nil) nil
(predicate (first sequence))
(cons (first sequence) (lazy-seq (filter-lazy-seq predicate
(rest sequence))))
:else (filter-lazy-seq predicate (rest sequence))))
(defn natural-gen []
(letfn [(helper [n]
(cons n (lazy-seq (helper2 (inc n)))))]
(helper 1))
)
(def naturals (natural-gen))