=> (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