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 <jawo...@berkeley.edu> wrote:
>
>> 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)"
>      [seqs]
>      (if (empty? seqs) '(())
>        (let [rec (combinations (rest seqs))]
>          (for [item (first seqs)
>                rst rec]
>            (cons item rst)))))
>
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to