Массивы и коллекции / Итераторы

;; Clojure has no yield: a generator here is a
;; lazy sequence, nothing is counted until asked
(defn counter [low high step]
  (take-while #(<= % high) (iterate #(+ % step) low)))

(doseq [c (counter 3 9 2)]
  (println c))
;; printed 3, 5, 7, 9

;; range is the ready-made counter
(println (vec (range 3 10 2)))
;; [3 5 7 9]

;; iterate alone is endless - take must cut it,
;; or the program will never stop
(println (take 4 (iterate #(* 2 %) 1)))
;; (1 2 4 8)