Re: difference between first & peek; rest & pop

2017-11-10 Thread Gary Verhaegen
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, rest, next and conj are part of the sequence abstraction; use them
when you're logically manipulating a sequence.

peek, pop and conj can be part of either the stack abstraction (if used on
lists or vectors) or the queue abstraction (if used on persistent queues).

Because Clojure is highly polymorphic, some names, like conj, can be (and
are) reused across abstractions, because they have very similar meanings
(e.g. "add something" for conj). You still have to know what context you're
using them in in order to understand exactly what they're going to do (e.g.
conj on a vector or on a seq across the same vector will not do the same
thing).

On 10 November 2017 at 12:49, Justin Smith  wrote:

> 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, vectors push and pop from the end,
> queues push to one end, pop from the other
>
> On Thu, Nov 9, 2017 at 6:06 PM Ethan Brooks 
> wrote:
>
>> 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 sequences..
>>>
>>> Thanks!
>>>
>>> Best,
>>>
>>> Seven Hong
>>>
>> --
>> 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
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Clojure" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to clojure+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> 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
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: difference between first & peek; rest & pop

2017-11-10 Thread Justin Smith
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, vectors push and pop from the end,
queues push to one end, pop from the other

On Thu, Nov 9, 2017 at 6:06 PM Ethan Brooks  wrote:

> 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 sequences..
>>
>> Thanks!
>>
>> Best,
>>
>> Seven Hong
>>
> --
> 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
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: difference between first & peek; rest & pop

2017-11-09 Thread Ethan Brooks
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 sequences..
>
> Thanks!
>
> Best,
>
> Seven Hong
>

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: difference between first peek; rest pop

2013-05-29 Thread Michał Marczyk
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 sequences (try (peek (range))
or (peek (cons :foo ())) at the REPL).

In general, they operate on clojure.lang.IPersistentStack instances.
(That's right, persistent queues implement IPersistentStack.)

Cheers,
Michał


On 30 May 2013 06:43, Seven Hong sir.seven.h...@gmail.com 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 sequences..

 Thanks!

 Best,

 Seven Hong

 --
 --
 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
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.



-- 
-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.