diff options
author | Rich Hickey <richhickey@gmail.com> | 2009-01-28 19:23:14 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2009-01-28 19:23:14 +0000 |
commit | 3ff5b944cd03878ea0ddfc3a345ea090bda37f1c (patch) | |
tree | 74cf7dbde0957dc0b183c6bf87b1e323d484d694 | |
parent | e9a429235b57b1d6b99102aa78180c6f0415d324 (diff) |
[lazy] added Seqable
-rw-r--r-- | src/jvm/clojure/lang/APersistentVector.java | 4 | ||||
-rw-r--r-- | src/jvm/clojure/lang/IPersistentCollection.java | 4 | ||||
-rw-r--r-- | src/jvm/clojure/lang/ISeq.java | 4 | ||||
-rw-r--r-- | src/jvm/clojure/lang/PersistentQueue.java | 4 | ||||
-rw-r--r-- | src/jvm/clojure/lang/RT.java | 8 | ||||
-rw-r--r-- | src/jvm/clojure/lang/Seqable.java | 17 |
6 files changed, 28 insertions, 13 deletions
diff --git a/src/jvm/clojure/lang/APersistentVector.java b/src/jvm/clojure/lang/APersistentVector.java index fe891ef7..4cb753a8 100644 --- a/src/jvm/clojure/lang/APersistentVector.java +++ b/src/jvm/clojure/lang/APersistentVector.java @@ -72,7 +72,7 @@ static boolean doEquals(IPersistentVector v, Object obj){ { if(!(obj instanceof Sequential)) return false; - ISeq ms = ((IPersistentCollection) obj).seq(); + ISeq ms = RT.seq(obj); for(int i = 0; i < v.count(); i++, ms = ms.rest()) { if(ms == null || !Util.equals(v.nth(i), ms.first())) @@ -115,7 +115,7 @@ static boolean doEquiv(IPersistentVector v, Object obj){ { if(!(obj instanceof Sequential)) return false; - ISeq ms = ((IPersistentCollection) obj).seq(); + ISeq ms = RT.seq(obj); for(int i = 0; i < v.count(); i++, ms = ms.rest()) { if(ms == null || !Util.equiv(v.nth(i), ms.first())) diff --git a/src/jvm/clojure/lang/IPersistentCollection.java b/src/jvm/clojure/lang/IPersistentCollection.java index a79534ae..40e0f283 100644 --- a/src/jvm/clojure/lang/IPersistentCollection.java +++ b/src/jvm/clojure/lang/IPersistentCollection.java @@ -11,12 +11,10 @@ package clojure.lang; */
-public interface IPersistentCollection {
+public interface IPersistentCollection extends Seqable {
int count();
-ISeq seq();
-
IPersistentCollection cons(Object o);
IPersistentCollection empty();
diff --git a/src/jvm/clojure/lang/ISeq.java b/src/jvm/clojure/lang/ISeq.java index dead741e..2e7adb3b 100644 --- a/src/jvm/clojure/lang/ISeq.java +++ b/src/jvm/clojure/lang/ISeq.java @@ -1,5 +1,3 @@ -package clojure.lang;
-
/**
* Copyright (c) Rich Hickey. All rights reserved.
* The use and distribution terms for this software are covered by the
@@ -10,6 +8,8 @@ package clojure.lang; * You must not remove this notice, or any other, from this software.
*/
+package clojure.lang;
+
/**
* A persistent, functional, sequence interface
* <p/>
diff --git a/src/jvm/clojure/lang/PersistentQueue.java b/src/jvm/clojure/lang/PersistentQueue.java index 0d2ec9a9..552cdb42 100644 --- a/src/jvm/clojure/lang/PersistentQueue.java +++ b/src/jvm/clojure/lang/PersistentQueue.java @@ -41,7 +41,7 @@ public boolean equiv(Object obj){ if(!(obj instanceof Sequential))
return false;
- ISeq ms = ((IPersistentCollection) obj).seq();
+ ISeq ms = RT.seq(obj);
for(ISeq s = seq(); s != null; s = s.rest(), ms = ms.rest())
{
if(ms == null || !Util.equiv(s.first(), ms.first()))
@@ -55,7 +55,7 @@ public boolean equals(Object obj){ if(!(obj instanceof Sequential))
return false;
- ISeq ms = ((IPersistentCollection) obj).seq();
+ ISeq ms = RT.seq(obj);
for(ISeq s = seq(); s != null; s = s.rest(), ms = ms.rest())
{
if(ms == null || !Util.equals(s.first(), ms.first()))
diff --git a/src/jvm/clojure/lang/RT.java b/src/jvm/clojure/lang/RT.java index a277f89e..8e3a7fab 100644 --- a/src/jvm/clojure/lang/RT.java +++ b/src/jvm/clojure/lang/RT.java @@ -447,8 +447,8 @@ static public ISeq seq(Object coll){ return null; else if(coll instanceof ISeq) return (ISeq) coll; - else if(coll instanceof IPersistentCollection) - return ((IPersistentCollection) coll).seq(); + else if(coll instanceof Seqable) + return ((Seqable) coll).seq(); else return seqFrom(coll); } @@ -722,7 +722,7 @@ static public Object nth(Object coll, int n){ else if(coll instanceof Sequential) { - ISeq seq = ((IPersistentCollection) coll).seq(); + ISeq seq = RT.seq(coll); coll = null; for(int i = 0; i <= n && seq != null; ++i, seq = seq.rest()) { @@ -785,7 +785,7 @@ static public Object nth(Object coll, int n, Object notFound){ } else if(coll instanceof Sequential) { - ISeq seq = ((IPersistentCollection) coll).seq(); + ISeq seq = RT.seq(coll); coll = null; for(int i = 0; i <= n && seq != null; ++i, seq = seq.rest()) { diff --git a/src/jvm/clojure/lang/Seqable.java b/src/jvm/clojure/lang/Seqable.java new file mode 100644 index 00000000..395a4d22 --- /dev/null +++ b/src/jvm/clojure/lang/Seqable.java @@ -0,0 +1,17 @@ +/** + * Copyright (c) Rich Hickey. All rights reserved. + * The use and distribution terms for this software are covered by the + * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) + * which can be found in the file epl-v10.html at the root of this distribution. + * By using this software in any fashion, you are agreeing to be bound by + * the terms of this license. + * You must not remove this notice, or any other, from this software. + **/ + +/* rich Jan 28, 2009 */ + +package clojure.lang; + +public interface Seqable { + ISeq seq(); +} |