ISeq inherits Sequential, but IPersistentStack does not

62 views
Skip to first unread message

Chouser

unread,
Jan 23, 2011, 4:44:39 PM1/23/11
to cloju...@googlegroups.com
Collection equality in Clojure is split into three partitions of
types: sequentials, maps, and sets. Finger-tree's
counted-sorted-set is primarily a set, but also supports walking
from either end (first/rest from the left, peek/pop from the
right), so my intention was for it to be in the "set" equality
partition, but to implement ISeq (for first/rest) and
IPersistentStack (for peek/pop) as well.

However, ISeq extends Sequential, which is what collections like
vector use to determine equality partition membership. Left this
way, using = to compare a vector and a counted-sorted-set with
the same contents will return true.

Interestingly, IPersistentStack does not extend Sequential.

So, should ISeq be changed to no longer directly extend
Sequential? Or perhaps counted-sorted-seq should participate
fully in both the set and sequential equality partitions? Is
there another option I'm not considering?

--Chouser
http://joyofclojure.com/

Rich Hickey

unread,
Jan 26, 2011, 7:39:45 AM1/26/11
to cloju...@googlegroups.com

On Jan 23, 2011, at 4:44 PM, Chouser wrote:

> Collection equality in Clojure is split into three partitions of
> types: sequentials, maps, and sets. Finger-tree's
> counted-sorted-set is primarily a set, but also supports walking
> from either end (first/rest from the left, peek/pop from the
> right), so my intention was for it to be in the "set" equality
> partition, but to implement ISeq (for first/rest) and
> IPersistentStack (for peek/pop) as well.
>
> However, ISeq extends Sequential, which is what collections like
> vector use to determine equality partition membership. Left this
> way, using = to compare a vector and a counted-sorted-set with
> the same contents will return true.
>
> Interestingly, IPersistentStack does not extend Sequential.
>
> So, should ISeq be changed to no longer directly extend
> Sequential?

Yes. Care will be required in making sure all appropriate concrete
derivees remain Sequential. It's a breaking change in that some
derivees not in Clojure may be relying on the derivation from ISeq, so
let's get this in now please.

Interface derivation stinks in general, it's just a major pain to do
without in Java.

Thanks,

Rich

Chouser

unread,
Feb 19, 2011, 2:21:11 AM2/19/11
to Clojure Dev
Reply all
Reply to author
Forward
0 new messages