Having separate "peek" and "last", with documented performance characteristics, makes it straightforward to reason about how code is likely to perform, a point that Mark made earlier.
It is a fundamental design principle of Clojure that, when given two approaches, A and B, make primitive the one that could be used to build the other. Clojure's "peek" and "last" might be useful to somebody building the "last" that Warren wants. Warren's "last" is *useless* for building the "peek" and "last" that Clojure already has. Not arguing against having Warren's "last". Just saying that c.c/last ain't broken, and is simpler. Stu > Even not a single action is taken because of this thread, I still would not > consider the thread fruitless. It helped me (and maybe others) understand the > issue better. > > My point was: you need a clear documentation on a coherent, consistent > abstraction, and let the programmer to understand. Just clear documentation > is not enough. You can document a very messy system in clear documentation > (maybe the US tax code?). > > Here, we are having both "peek" and "last", which is not coherent to me. > consider the documentation on an alternative design: > > last: get the last element from an ordered collection. for queues and linked > lists, it takes linear time. for vectors, it takes constant time. > > and get rid of "peek" (we already have "first" for linked list and queues, > right?) > > Which one is cleaner? > > > On Friday, June 29, 2012 3:27:57 PM UTC-4, Sean Corfield wrote: > On Fri, Jun 29, 2012 at 7:51 AM, Warren Lynn <wrn.l...@gmail.com> wrote: > > 1. Put good documentations on the functions, and the programmer needs to > > have some idea what data structure is fast/slow for what use. > > At the risk of continuing what is quickly becoming a rather fruitless > thread, I figured I'd quote the docstrings from last and peek: > > last: Return the last item in coll, in linear time > > peek: For a list or queue, same as first, for a vector, same as, but > much more efficient than, last. If the collection is empty, returns > nil. > > That seems like pretty good documentation to me. (last my-vector) is > documented to be a linear operation. (peek my-vector) is documented to > be "much more efficient". last is not dependent on the type of its > argument, peek is. > -- > Sean A Corfield -- (904) 302-SEAN > An Architect's View -- http://corfield.org/ > World Singles, LLC. -- http://worldsingles.com/ > > "Perfection is the enemy of the good." > -- Gustave Flaubert, French realist novelist (1821-1880) > > -- > 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 members are moderated - please be patient with your > first post. > 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 Stuart Halloway Clojure/core http://clojure.com -- 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 members are moderated - please be patient with your first post. 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