Re: super-lazy-seq

2009-06-15 Thread Daniel Lyons
On Jun 12, 2009, at 7:52 PM, Wrexsoul wrote: > Well, I did it. Made implementing lazy seqs that require stateful > generator functions easy, that is: > > (defn files-and-dirs-recursive [dir] > (super-lazy-seq [stack [(to-file dir)]] >(if-not (empty? stack) > (let [file (first stack) s

Re: super-lazy-seq

2009-06-15 Thread James Reeves
On Jun 15, 4:58 am, Wrexsoul wrote: > Eh. That didn't occur to me. It could be combined with the meta-nil > trick, too: > > (defn custom-lazy-seq [genfn] >   (map #(first %) >     (take-while (complement nil?) >       (repeatedly genfn > > where the genfn returns nil for no-next-item and [i

Re: super-lazy-seq

2009-06-15 Thread Daniel Lyons
On Jun 14, 2009, at 12:53 PM, James Reeves wrote: > > On Jun 14, 6:32 pm, Wrexsoul wrote: >> I wrote super-lazy-seq because repeatedly can't generate a finite >> sequence. It just spat out >> >> (File1 File2 File3 File4 nil nil nil nil nil nil nil ... > > Well, you could wrap it in take-while:

Re: super-lazy-seq

2009-06-14 Thread Wrexsoul
On Jun 14, 2:53 pm, James Reeves wrote: > On Jun 14, 6:32 pm, Wrexsoul wrote: > > > I wrote super-lazy-seq because repeatedly can't generate a finite > > sequence. It just spat out > > > (File1 File2 File3 File4 nil nil nil nil nil nil nil ... > > Well, you could wrap it in take-while: > >   (de

Re: super-lazy-seq

2009-06-14 Thread James Reeves
On Jun 14, 6:32 pm, Wrexsoul wrote: > I wrote super-lazy-seq because repeatedly can't generate a finite > sequence. It just spat out > > (File1 File2 File3 File4 nil nil nil nil nil nil nil ... Well, you could wrap it in take-while: (defn custom-lazy-seq [stream] (take-while (complement n

Re: super-lazy-seq

2009-06-14 Thread Wrexsoul
On Jun 14, 9:39 am, James Reeves wrote: > Okay, but don't underestimate the power of higher level functions. I > don't know whether it would apply to your code, but the repeatedly > function can be used to create a lazy seq from a function with side- > effects. > > For example: > >   (defn custom

Re: super-lazy-seq

2009-06-14 Thread James Reeves
On Jun 14, 4:37 am, Wrexsoul wrote: > Seems to me that unless you completely consume the sequence, it will > leak a file handle. That's true, but that's a problem that affects all seqs. There's no current way to mark a seq that comes from a stream as being discarded or closed, except by closing

Re: super-lazy-seq

2009-06-14 Thread Jarkko Oranen
On Jun 14, 6:37 am, Wrexsoul wrote: > On Jun 13, 11:07 pm, James Reeves wrote: > > > For instance, lets say I want to return a lazy list of all the lines > > in all the files in a directory tree: > > >   (use '(clojure.contrib java-utils > >                          duck-streams)) > > When cloju

Re: super-lazy-seq

2009-06-13 Thread Wrexsoul
On Jun 13, 11:07 pm, James Reeves wrote: > For instance, lets say I want to return a lazy list of all the lines > in all the files in a directory tree: > >   (use '(clojure.contrib java-utils >                          duck-streams)) When clojure.contrib releases version 1.0, that might be an op

Re: super-lazy-seq

2009-06-13 Thread James Reeves
On Jun 14, 3:21 am, Wrexsoul wrote: > It lets you write the generator in a style similar to loop/recur, and > generally in half the code. And, it demonstrates the kinds of things > you can do with macros. Ahh, I see. That could be useful under some circumstances. However, most Clojure functions

Re: super-lazy-seq

2009-06-13 Thread Wrexsoul
On Jun 13, 9:24 pm, James Reeves wrote: > On Jun 13, 4:18 am, Wrexsoul wrote: > > > Between files-and-dirs and file-lines-seq I think I have saved as many > > lines of code as are in the macro+helper fns, so those are at break- > > even. > > I'm not completely sure what benefit super-lazy-seq is

Re: super-lazy-seq

2009-06-13 Thread James Reeves
On Jun 13, 4:18 am, Wrexsoul wrote: > Between files-and-dirs and file-lines-seq I think I have saved as many > lines of code as are in the macro+helper fns, so those are at break- > even. I'm not completely sure what benefit super-lazy-seq is meant to have. Could you perhaps give an example writ

Re: super-lazy-seq

2009-06-12 Thread Wrexsoul
Heh. Thought of an improvement: (defn make-atom-setter-fn-expr [names skip?] (let [arglist-1 (map #(gensym %) names) arglist (vec (if skip? arglist-1 (cons (gensym 'item) arglist-1)))] `(~(if skip? 'skip-item 'next-item) ~arglist ~@(map (fn [nm gs] (list 'reset! nm gs))