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
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
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
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
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
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
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
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
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.