On Nov 15, 11:15 am, samppi <[EMAIL PROTECTED]> wrote:
> Is there a way to make a lazy sequence whose sequential values are
> derived from some function? I'm thinking about two ways:
>
>     (recursive-fn-seq f initial [n]) ; returns (initial (f initial) (f
> (f initial)) ...) n or infinity times
(defn all-same [i] (lazy-cons i (all-same i)))

(take 3 (map inc (all-same 1)))
=> '(2 2 2)

>     (index-fn-seq f initial [n]); returns ((f i) (f (inc i)) (f (inc
> (inc i))) ...) to i = n or infinity
(defn intseq [i] (lazy-cons i (intseq (inc i))))

(take 3 (map inc (intseq 1)))
=> '(2 3 4)

Best,

--
Michel
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to