Ah! I knew there was a way to do it via iterate, but it was 9:30pm at the
time and I was tired. Nice example though.
On Tue, Dec 13, 2016 at 10:03 PM, Ghadi Shayban <gshay...@gmail.com> wrote:

> A common way to do it in Clojure is `iterate`, no macros necessary. As of
> Clojure 1.7 this doesn't allocate a list at all if you reduce/fold over it:
> (iterate #(+ % 2) 4)
>
>
> On Tuesday, December 13, 2016 at 11:27:28 PM UTC-5, tbc++ wrote:
>>
>> I'm not aware of such a construct, but it's trivial enough to write
>> something like this using `range` or perhaps write a function that will
>> yield a lazy seq:
>>
>> (defn inf-list
>>   ([x y]
>>     (cons x (cons y (inf-list x y 2))))
>>   ([x y c]
>>     (cons (+ x (* c (- y x)))
>>       (lazy-seq (inf-list x y (inc c))))))
>>
>> No macros required
>>
>> On Tue, Dec 13, 2016 at 9:14 PM, bill nom nom <hellomot...@gmail.com>
>> wrote:
>>
>>> In Haskell, I can get an infinite lazy list that is incremented by two
>>> by, starting at 4
>>> [4,6..]
>>>
>>> which yields the result
>>> [4,6,8,10...]
>>>
>>> the more general form
>>> [x,y..] produces [x, x + (y-x), x + 2 * (y-x), x + 3 * (y-x)...]
>>>
>>> Is there a way to make a macro of this in clojure, or is there something
>>> already as elegant?
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Clojure" group.
>>> To post to this group, send email to clo...@googlegroups.com
>>> Note that posts from new members are moderated - please be patient with
>>> your first post.
>>> To unsubscribe from this group, send email to
>>> clojure+u...@googlegroups.com
>>> For more options, visit this group at
>>> http://groups.google.com/group/clojure?hl=en
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "Clojure" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to clojure+u...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> “One of the main causes of the fall of the Roman Empire was that–lacking
>> zero–they had no way to indicate successful termination of their C
>> programs.”
>> (Robert Firth)
>>
> --
> 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
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
“One of the main causes of the fall of the Roman Empire was that–lacking
zero–they had no way to indicate successful termination of their C
programs.”
(Robert Firth)

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to