Re: (clojure.contrib.lazy-seqs/combinations) should return [[]], not nil?

2009-01-26 Thread Jason Wolfe
On Jan 26, 2009, at 4:24 PM, Mark Engelberg wrote: > > Hey, I just looked back at the original post that started the thread. > At some point, I had changed my function so (cartesian-product) > returned nil instead of (nil), but based on Jason's post, I've changed > it back in another paste annotat

Re: (clojure.contrib.lazy-seqs/combinations) should return [[]], not nil?

2009-01-26 Thread Mark Engelberg
Hey, I just looked back at the original post that started the thread. At some point, I had changed my function so (cartesian-product) returned nil instead of (nil), but based on Jason's post, I've changed it back in another paste annotation. --~--~-~--~~~---~--~~ Y

Re: (clojure.contrib.lazy-seqs/combinations) should return [[]], not nil?

2009-01-26 Thread Mark Engelberg
I updated the paste with the changes we've discussed. http://paste.lisp.org/display/74134#3 I'll keep playing around to see if I can get it faster, but so far, this is the fastest way I've found to generate the cartesian product in standard order. --~--~-~--~~~---~--

Re: (clojure.contrib.lazy-seqs/combinations) should return [[]], not nil?

2009-01-26 Thread Jason Wolfe
On Jan 26, 2009, at 10:28 AM, Mark Engelberg wrote: > > I've tested that already, and it takes even longer for all but trivial > inputs, because rec now prevents the combinations sequence from being > garbage collected, and the memory allocation bogs things down > tremendously. Ah, I noticed the

Re: (clojure.contrib.lazy-seqs/combinations) should return [[]], not nil?

2009-01-26 Thread Mark Engelberg
I've tested that already, and it takes even longer for all but trivial inputs, because rec now prevents the combinations sequence from being garbage collected, and the memory allocation bogs things down tremendously. On Mon, Jan 26, 2009 at 10:26 AM, Jason Wolfe wrote: > >> Also, it's worth poin

Re: (clojure.contrib.lazy-seqs/combinations) should return [[]], not nil?

2009-01-26 Thread Jason Wolfe
> Also, it's worth pointing out that your newer version prints the > combinations out in a non-standard order. Good point ... I shouldn't have tried to avoid adding the "let": (defn combinations "Take a seq of seqs and return a lazy list of ordered combinations (pick 1 from each seq)" [seq

Re: (clojure.contrib.lazy-seqs/combinations) should return [[]], not nil?

2009-01-26 Thread Jason Wolfe
> > For simple inputs, the two approaches have similar performance. On > complex inputs, my tests show the iterative version tends to run about > twice as fast. > > Try running on an extreme input like: > ["ACDFG" "A" "B" "C" "D" "E" "F" "ABCD" "G" "H" "I" "ABEG" "J" "K" > "BCDE" "L" "ABCDG" "M"

Re: (clojure.contrib.lazy-seqs/combinations) should return [[]], not nil?

2009-01-26 Thread Mark Engelberg
Also, it's worth pointing out that your newer version prints the combinations out in a non-standard order. I don't know whether people should really rely on the order, but I think most people would expect it to print out in the same order as a series of nested for loops. --~--~-~--~~

Re: (clojure.contrib.lazy-seqs/combinations) should return [[]], not nil?

2009-01-25 Thread Mark Engelberg
For simple inputs, the two approaches have similar performance. On complex inputs, my tests show the iterative version tends to run about twice as fast. Try running on an extreme input like: ["ACDFG" "A" "B" "C" "D" "E" "F" "ABCD" "G" "H" "I" "ABEG" "J" "K" "BCDE" "L" "ABCDG" "M" "EF" "NABC" "AB

Re: (clojure.contrib.lazy-seqs/combinations) should return [[]], not nil?

2009-01-25 Thread Jason Wolfe
OK, cartesian_product it is. Two comments on your version. First, unlike mine (and the current "combinations"), it takes a single argument, a seq of seqs (rather than multiple seq arguments); which of these ways is preferred? Second, I had the clauses of my for loop backwards, which was slowing

Re: (clojure.contrib.lazy-seqs/combinations) should return [[]], not nil?

2009-01-24 Thread Mark Engelberg
On Fri, Jan 23, 2009 at 11:43 PM, wrote: > I think the usual mathematical name is be cartesian-product (or maybe > cross-product), although selections is OK with me too. Yes, now that you've reminded me, I agree that cartesian-product is the usual mathematical name, and that would probably be m

Re: (clojure.contrib.lazy-seqs/combinations) should return [[]], not nil?

2009-01-23 Thread jawolfe
> On Fri, Jan 23, 2009 at 8:49 PM, Chouser wrote: >> This is the best version? > > Depends on your definition of "best". > > I just posted a version at http://paste.lisp.org/display/74134 which > is many times faster. I haven't had a chance to look at that in detail yet, but I'm 100% in favor of

Re: (clojure.contrib.lazy-seqs/combinations) should return [[]], not nil?

2009-01-23 Thread Mark Engelberg
On Fri, Jan 23, 2009 at 8:49 PM, Chouser wrote: > This is the best version? Depends on your definition of "best". I just posted a version at http://paste.lisp.org/display/74134 which is many times faster. Also, I have to say that calling this function "combinations" is fairly nonstandard. Usu

Re: (clojure.contrib.lazy-seqs/combinations) should return [[]], not nil?

2009-01-23 Thread Chouser
On Fri, Jan 23, 2009 at 1:11 PM, Stephen C. Gilardi wrote: > > Please do enter it as an issue. I'd be interested in hearing from Chouser > before making the change. He added combinations to lazy-seqs. I did what now? My memory must be going. Here are some other implementations I apparently wen

Re: (clojure.contrib.lazy-seqs/combinations) should return [[]], not nil?

2009-01-23 Thread Jason Wolfe
> > On Jan 23, 2009, at 1:11 PM, Stephen C. Gilardi wrote: > >> I'd be interested in hearing from Chouser before making the change. >> He added combinations to lazy-seqs. > > I think it's quite cool that simply removing the "when" accomplishes > this. Yes, exactly :) Returning nil for no-arg

Re: (clojure.contrib.lazy-seqs/combinations) should return [[]], not nil?

2009-01-23 Thread Stephen C. Gilardi
On Jan 23, 2009, at 1:11 PM, Stephen C. Gilardi wrote: I'd be interested in hearing from Chouser before making the change. He added combinations to lazy-seqs. I think it's quite cool that simply removing the "when" accomplishes this. --Steve smime.p7s Description: S/MIME cryptographic

Re: (clojure.contrib.lazy-seqs/combinations) should return [[]], not nil?

2009-01-23 Thread Stephen C. Gilardi
On Jan 23, 2009, at 12:53 PM, Jason Wolfe wrote: Just to clarify: I dont' care what the type of the output is. I guess (seq [[]]) would actually be more consistent with the existing function. The point is that the output of 0-arg combinations should be a seq containing an empty vector (or wha

Re: (clojure.contrib.lazy-seqs/combinations) should return [[]], not nil?

2009-01-23 Thread Jason Wolfe
Just to clarify: I dont' care what the type of the output is. I guess (seq [[]]) would actually be more consistent with the existing function. The point is that the output of 0-arg combinations should be a seq containing an empty vector (or whatever other types, I don't care), not an empty seq.

(clojure.contrib.lazy-seqs/combinations) should return [[]], not nil?

2009-01-21 Thread Jason Wolfe
I just got bit by (clojure.contrib.lazy-seqs/combinations) returning nil, not [[]] as I expected. I could see arguments for either being the "correct" output, but let me give my case for [[]]. In my mind, asking what the output of (combinations) should be is completely analogous to asking what t