Another flatten thread! Sorry..
Hello all, before I realized there was a flatten in the master branch
(and before I looked at contrib) I wrote this pretty standard code:
(defn my-flatten [coll]
(lazy-seq
(when-let [coll (seq coll)]
(let [x (first coll)]
(if (sequential? x)
Unless you wrap a "doall" around the calls to flatten and my-flatten,
you're not really timing anything relevant.
--
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 me
Hi Cam,
Your tests aren't testing the interesting part without a doall.
That said, my quick tests with doall show your approach faring even better. :-)
Also, I think what my-flatten does with Java arrays is intuitive (and the
current flatten not so much).
A patch that preserves the semantics
Hi Stuart,
Thanks for checking that out for me! Sorry for not realizing in the
first place.
I of course would be happy to submit a patch. Should I submit that
here or over on the assembla page?
On Jul 13, 9:10 am, Stuart Halloway wrote:
> Hi Cam,
>
> Your tests aren't testing the interesting pa
Hi Cam,
The full instructions for joining the team and then submitting a patch are at
[1] an [2], but in short:
* send in a CA
* join the Assembla space under you real name
* post a patch there linking to this thread
Thanks!
Stu
[1] http://clojure.org/contributing
[2] http://clojure.org/patche
Hi again, I modified my-flatten to return the empty list for sets and
maps as core/flatten does. It doesn't seem to handle Arrays anymore
though. I'm assuming it's because ArrayList and (int-array ...) don't
implement Sequential. None the less should I still submit this
modified version that behave
Hi Cam,
Please submit the modified version, and, if you want, create a separate ticket
for "seqable?". I would like to review the latter separately.
Stu
> Hi again, I modified my-flatten to return the empty list for sets and
> maps as core/flatten does. It doesn't seem to handle Arrays anymore
OK, all submitted. The tickets are up for discussion at
http://www.assembla.com/spaces/clojure/support/tickets/400-a-faster-flatten
http://www.assembla.com/spaces/clojure/support/tickets/401-promote--seqable---from-contrib-
I will mail my CA in tomorrow morning.
Thanks Stu and Mark!
On Jul 13
I think it's worthwhile to have a faster flatten even if it doesn't
look as elegant as the current implementation. You could do a bit of
refactoring and save yourself a call to sequential? since the
recursive calls are guaranteed to have seqs (as a result of next).
Also, I'd pr
I definitely like this version a little better. If you change the else
of the if to be just (list), it returns the empty list just as core/
flatten does. Mind if I update the ticket with this patch?
On Jul 14, 1:56 pm, miner wrote:
> I think it's worthwhile to have a faster flatten ev
On Jul 14, 2010, at 2:40 PM, Cam wrote:
> I definitely like this version a little better. If you change the else
> of the if to be just (list), it returns the empty list just as core/
> flatten does. Mind if I update the ticket with this patch?
It's all yours. Really, just a slight change from
You're right about rest, I didn't see that rest should be preferred to
next when consuming seqs in this style.
I agree that flatten returning the empty list for some of the things
that actually can be "seqed" is odd. I'm sure there's a good reason
somewhere, but it's not to hard to change by just
12 matches
Mail list logo