Re: a better reductions?

2009-08-09 Thread Daniel Werner
On Aug 7, 8:40 pm, Vagif Verdi vagif.ve...@gmail.com wrote: I'd suggest to include into library for teaching purposes variants of unoptimized functions with a suffix -naive. Say reduction-naive. This way you could have both beautiful algorithm for teaching purposes, and optimized function for

Re: a better reductions?

2009-08-07 Thread Lauri Pesonen
Hi Stuart, 2009/8/6 Stuart Halloway stuart.hallo...@gmail.com: On the plus side, it appears to be faster (as collections grow large), and it doesn't cheat by introducing an atom. On the minus side it isn't as pretty as the one in contrib. While maybe not as pretty as the one in contrib,

Re: a better reductions?

2009-08-07 Thread Daniel Lyons
On Aug 7, 2009, at 2:59 AM, Lauri Pesonen wrote: While maybe not as pretty as the one in contrib, it's not a monster either. Shouldn't we aim for efficiency rather than elegance in library routines (within reason)? I think the user will appreciate the speedy version more than the pretty

Re: a better reductions?

2009-08-07 Thread Sean Devlin
I have to revise my last recommendation. The signature of the second call should be [f val coll] in order to match reduce. Admittedly, this is a tiny detail. Sean On Aug 6, 4:28 pm, Sean Devlin francoisdev...@gmail.com wrote: One more thought.  I'd change the signature of the second call

Re: a better reductions?

2009-08-07 Thread Mark Engelberg
I believe that if you're going for speed, another trick is to use if-let to bind a name to (seq coll) and reuse the new name, rather than coll, when applying first and rest later in the function. --~--~-~--~~~---~--~~ You received this message because you are

Re: a better reductions?

2009-08-07 Thread Vagif Verdi
On Aug 7, 1:23 am, Daniel Lyons fus...@storytotell.org wrote: This is the difference between FreeBSD and NetBSD. I agree, but I also   find it useful to crack open core and contrib to see coding examples   and to understand algorithms. I'd suggest to include into library for teaching

a better reductions?

2009-08-06 Thread Stuart Halloway
Is the following an improvement on clojure.contrib.seq-utils/ reductions, or a step backwards? (defn my-reductions ([f coll] (if (seq coll) (cons (first coll) (my-reductions f (first coll) (rest coll))) (cons (f) nil))) ([f acc coll] (if (seq coll) (let

Re: a better reductions?

2009-08-06 Thread Sean Devlin
One more thought. I'd change the signature of the second call to [f init coll] This matches the original reductions. On Aug 6, 4:20 pm, Sean Devlin francoisdev...@gmail.com wrote: It seems to have the same signature, so as a consumer of the library it's the same to me.  If the speedup