Currently only vectors and lists implement the stack interfaces, not seqs. 
I do not think it makes sense for *all* seqs to implement the stack 
interface. It may not even make sense for any seqs to implement it, but I'd 
have to think about think about that for a while. Feel free to file an 
enhancement in jira if you like.

On Saturday, June 11, 2016 at 1:37:26 PM UTC-5, Fluid Dynamics wrote:
>
> => (pop '(1 2 3))
> (2 3)
> => (pop (seq '(1 2 3)))
> (2 3)
> => ((fn [& xs] (pop xs)) '(1 2 3))
> ClassCastException clojure.lang.ArraySeq cannot be cast to 
> clojure.lang.IPersistentStack
> => (pop (map inc (take 5 (iterate inc 0))))
> ClassCastException clojure.lang.LazySeq cannot be cast to 
> clojure.lang.IPersistentStack
>
> That's not right. Pop should act the same as next on all seqs. Instead it 
> seems to care about details of how the seq was obtained. This clearly 
> violates least surprise.
>
> Even wrapping in seq doesn't save you:
>
> => (pop (seq (map inc (take 5 (iterate inc 0)))))
> ClassCastException clojure.lang.Cons cannot be cast to 
> clojure.lang.IPersistentStack
>
> This despite (pop (seq '(1 2 3))) working. It *definitely* should be the 
> case that either (pop (seq x)) works for all non-empty x, or (pop (seq x)) 
> fails for all non-empty x!
>
> The obvious fix is to make Cons, LazySeq, ArraySeq, and possibly other 
> concrete seq/list-type objects that do not already do so implement 
> IPersistentStack, with peek and pop invoking first and next, respectively.
>

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

Reply via email to