Re: last and nth are bad?

2011-06-10 Thread James Estes
Per the doc, last is linear time, and the source doesn't check for reversible. user= (source last) (def ^{:arglists '([coll]) :doc Return the last item in coll, in linear time :added 1.0} last (fn last [s] (if (next s) (recur (next s)) (first s unless i'm

Aw: Re: last and nth are bad?

2011-06-10 Thread Meikel Brandmeyer
Hi, Am Freitag, 10. Juni 2011 06:49:41 UTC+2 schrieb Sunil Nandihalli: as long as (reversible? of-whatever-collection) is true , last is almost a constant time operation In theory, but not in practice. last will always be O(N) in it's current implementation. The only fast way to get the

Re: Re: last and nth are bad?

2011-06-10 Thread Sunil S Nandihalli
ah sorry for that.. But it looks like I have grown very complacent about clojure-functions doing the *right thing* .. my bad. Sunil. On Fri, Jun 10, 2011 at 12:06 PM, Meikel Brandmeyer m...@kotka.de wrote: Hi, Am Freitag, 10. Juni 2011 06:49:41 UTC+2 schrieb Sunil Nandihalli: as long as

Re: last and nth are bad?

2011-06-10 Thread clojurefanxx
It seems that when i get messages saying that You tripped the alarm! last is bad! or You tripped the alarm! nth is bad!, I'm merely being told not to use last or nth as the candidate solutions but instead to write my own functions that achieve the same goal. So the messages last is bad! or nth

Re: last and nth are bad?

2011-06-10 Thread Nick Zbinden
Shouldn't these funkitons take the most effective implementation iternaly? We allready have a internal reduce-protocoll why not have one for other functions like last? The seq library should only drop to first/rest if there is no better implementation. -- You received this message because you

last and nth are bad?

2011-06-09 Thread clojurefanxx
i'm a newbie working thru 4clojure.com's problems #19 thru #21 where i'm asked to write a function, which when given a list or vector, returns the last, penultimate, or an arbitrary nth element, respectively. for problem #19 (return last element), using the function last was not accepted as a

Re: last and nth are bad?

2011-06-09 Thread James Estes
I'm fairly new too, but I'll take a stab. I think the koan's for 19-21 are trying to make you do exactly what you are doing: consider the performance characteristics for various operations on a vector vs a list or sequence. Problem 19, for example, is highlighting that 1 - Last is slow for a

Re: last and nth are bad?

2011-06-09 Thread Sunil S Nandihalli
as long as (reversible? of-whatever-collection) is true , last is almost a constant time operation On Fri, Jun 10, 2011 at 8:20 AM, clojurefanxx neuzhou...@gmail.com wrote: i'm a newbie working thru 4clojure.com's problems #19 thru #21 where i'm asked to write a function, which when given a

Re: last and nth are bad?

2011-06-09 Thread Sean Corfield
On Thu, Jun 9, 2011 at 7:50 PM, clojurefanxx neuzhou...@gmail.com wrote: (i 'm assuming that's the reason why last, nth, and get were rejected when I tried them out as candidate solutions??) The 4clojure tests are intended to get you to write solutions without the simple, obvious function.