Using a dynamic language doesn't mean you should not think in terms of
(abstract) types; it only means that you're note relying on the compiler to
check types for you. If anything, that should encourage you to be more
disciplined in your thought processes (as you don't have anything else to
rely on
first and rest are defined in terms of position, and work on anything that
can be treated as an ordered collection
peek and pop work in terms of "natural insertion order" and only work with
things that behave like a stack - (so not lazy-seqs, strings, etc.)
lists push and pop from the front, vect
Also, pop throws an exception on the empty list whereas rest returns ().
On Thursday, May 30, 2013 at 12:43:14 AM UTC-4, Seven Hong wrote:
>
> Hi all,
>
> Could some one explain what's the difference between first and peek, rest
> and pop? For me it looks like they behave exactly same on sequence
They are equivalent when operating on lists, but not so when operating
on vectors (peek = constant time last, pop = log time remove last
element) or queues (peek = first, pop = remove first element returning
a queue -- rest/next would return a seq).
Also, they refuse to work with non-list sequence
Hi all,
Could some one explain what's the difference between first and peek, rest
and pop? For me it looks like they behave exactly same on sequences..
Thanks!
Best,
Seven Hong
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this g