Re: Elegant way to do lazy infinite list with custom step

2016-12-14 Thread Ghadi Shayban
If you really want to have _exactly_ what Haskell does (derives the range from an example) -- yes, you could do a macro. Clojure's new spec facility (in 1.9-alphas) makes the macro arguments checked at load time too, which is extra nice: (set! *print-length* 5) ;; avoid printing infinite

Re: Elegant way to do lazy infinite list with custom step

2016-12-13 Thread Timothy Baldridge
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 wrote: > A common way to do it in Clojure is `iterate`, no macros necessary. As of > Clojure 1.7 this doesn't

Re: Elegant way to do lazy infinite list with custom step

2016-12-13 Thread Ghadi Shayban
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

Re: Elegant way to do lazy infinite list with custom step

2016-12-13 Thread Alex Miller
(range 4 Long/MAX_VALUE 2) On Tuesday, December 13, 2016 at 10:14:00 PM UTC-6, bill nom nom 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,

Re: Elegant way to do lazy infinite list with custom step

2016-12-13 Thread Timothy Baldridge
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

Elegant way to do lazy infinite list with custom step

2016-12-13 Thread bill nom nom
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