diff options
author | Rich Hickey <richhickey@gmail.com> | 2006-08-04 23:13:37 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2006-08-04 23:13:37 +0000 |
commit | ae23e1e284833c61924cc09f4053ded4cc96cc44 (patch) | |
tree | db4d68569df44ec84825093ded8febed442accc6 | |
parent | b47c234ac5a398894c8f3ce5dc7c06a5e7926e10 (diff) |
added Sequential, Associative
-rw-r--r-- | src/cli/runtime/Associative.cs | 21 | ||||
-rw-r--r-- | src/cli/runtime/Cons.cs | 6 | ||||
-rw-r--r-- | src/cli/runtime/IPersistentCollection.cs | 2 | ||||
-rw-r--r-- | src/cli/runtime/IPersistentMap.cs | 11 | ||||
-rw-r--r-- | src/cli/runtime/PersistentArray.cs | 4 | ||||
-rw-r--r-- | src/cli/runtime/RT.cs | 5 | ||||
-rw-r--r-- | src/cli/runtime/Sequential.cs | 18 | ||||
-rw-r--r-- | src/cli/runtime/Tuple.cs | 4 | ||||
-rw-r--r-- | src/jvm/clojure/lang/Associative.java | 20 | ||||
-rw-r--r-- | src/jvm/clojure/lang/Cons.java | 4 | ||||
-rw-r--r-- | src/jvm/clojure/lang/IPersistentCollection.java | 1 | ||||
-rw-r--r-- | src/jvm/clojure/lang/IPersistentMap.java | 11 | ||||
-rw-r--r-- | src/jvm/clojure/lang/PersistentArray.java | 4 | ||||
-rw-r--r-- | src/jvm/clojure/lang/RT.java | 5 | ||||
-rw-r--r-- | src/jvm/clojure/lang/Sequential.java | 13 | ||||
-rw-r--r-- | src/jvm/clojure/lang/Tuple.java | 4 |
16 files changed, 112 insertions, 21 deletions
diff --git a/src/cli/runtime/Associative.cs b/src/cli/runtime/Associative.cs new file mode 100644 index 00000000..3f14089a --- /dev/null +++ b/src/cli/runtime/Associative.cs @@ -0,0 +1,21 @@ +/**
+ * Copyright (c) Rich Hickey. All rights reserved.
+ * The use and distribution terms for this software are covered by the
+ * Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
+ * which can be found in the file CPL.TXT 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.
+ */
+
+using System;
+namespace clojure.lang
+ {
+ public interface Associative
+ {
+ bool contains(object key);
+ IMapEntry find(object key);
+ object get(object key);
+ IPersistentMap put(object key, object val);
+ }
+ }
diff --git a/src/cli/runtime/Cons.cs b/src/cli/runtime/Cons.cs index 18c2a656..cd5291db 100644 --- a/src/cli/runtime/Cons.cs +++ b/src/cli/runtime/Cons.cs @@ -43,13 +43,17 @@ public ISeq rest() #endregion
-#region ISequential Members
+#region IPersistentCollection Members
public ISeq seq()
{
return this;
}
+public int count() {
+ return 1 + RT.count(_rest);
+}
+
#endregion
} diff --git a/src/cli/runtime/IPersistentCollection.cs b/src/cli/runtime/IPersistentCollection.cs index d908b7fb..6746240b 100644 --- a/src/cli/runtime/IPersistentCollection.cs +++ b/src/cli/runtime/IPersistentCollection.cs @@ -16,6 +16,8 @@ namespace clojure.lang public interface IPersistentCollection
{
+ int count();
+
ISeq seq();
}
diff --git a/src/cli/runtime/IPersistentMap.cs b/src/cli/runtime/IPersistentMap.cs index c91d3aa8..df91a08a 100644 --- a/src/cli/runtime/IPersistentMap.cs +++ b/src/cli/runtime/IPersistentMap.cs @@ -14,22 +14,13 @@ using System.Collections; namespace clojure.lang
{
-public interface IPersistentMap : IEnumerable, IPersistentCollection{
+public interface IPersistentMap : Associative, IEnumerable, IPersistentCollection{
-int count();
-
-bool contains(Object key);
-
-IMapEntry find(Object key);
IPersistentMap add(Object key, Object val);
-IPersistentMap put(Object key, Object val);
-
IPersistentMap remove(Object key);
-Object get(Object key);
-
int capacity();
}
diff --git a/src/cli/runtime/PersistentArray.cs b/src/cli/runtime/PersistentArray.cs index 73b7a369..2cabe49e 100644 --- a/src/cli/runtime/PersistentArray.cs +++ b/src/cli/runtime/PersistentArray.cs @@ -257,6 +257,10 @@ public PersistentArray(IArray init) :this(init.length()) { data.master.load = load;
}
+virtual public int count(){
+return data.master.array.Length;
+}
+
virtual public int length(){
return data.master.array.Length;
}
diff --git a/src/cli/runtime/RT.cs b/src/cli/runtime/RT.cs index 23cb34b3..ed6bfffe 100644 --- a/src/cli/runtime/RT.cs +++ b/src/cli/runtime/RT.cs @@ -379,5 +379,10 @@ static public Object setValues(params Object[] vals) return null;
}
+public static int count(Object o) {
+ if(o == null)
+ return 0;
+ return ((IPersistentCollection)o).count();
+}
}
}
\ No newline at end of file diff --git a/src/cli/runtime/Sequential.cs b/src/cli/runtime/Sequential.cs new file mode 100644 index 00000000..a8b48e96 --- /dev/null +++ b/src/cli/runtime/Sequential.cs @@ -0,0 +1,18 @@ +/**
+ * Copyright (c) Rich Hickey. All rights reserved.
+ * The use and distribution terms for this software are covered by the
+ * Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
+ * which can be found in the file CPL.TXT 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.
+ */
+
+namespace clojure.lang
+{ +
+
+public interface Sequential {
+}
+
+}
diff --git a/src/cli/runtime/Tuple.cs b/src/cli/runtime/Tuple.cs index 59799b30..7c6c2f02 100644 --- a/src/cli/runtime/Tuple.cs +++ b/src/cli/runtime/Tuple.cs @@ -29,6 +29,10 @@ public Tuple(params Object[] init){ this.array = init;
}
+public int count() {
+ return array.Length;
+}
+
public int length() {
return array.Length;
}
diff --git a/src/jvm/clojure/lang/Associative.java b/src/jvm/clojure/lang/Associative.java new file mode 100644 index 00000000..72318bdb --- /dev/null +++ b/src/jvm/clojure/lang/Associative.java @@ -0,0 +1,20 @@ +package clojure.lang;
+
+/**
+ * Copyright (c) Rich Hickey. All rights reserved.
+ * The use and distribution terms for this software are covered by the
+ * Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
+ * which can be found in the file CPL.TXT 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.
+ */
+public interface Associative {
+boolean contains(Object key);
+
+IMapEntry find(Object key);
+
+IPersistentMap put(Object key, Object val);
+
+Object get(Object key);
+}
diff --git a/src/jvm/clojure/lang/Cons.java b/src/jvm/clojure/lang/Cons.java index 9d2895a1..aac9fe36 100644 --- a/src/jvm/clojure/lang/Cons.java +++ b/src/jvm/clojure/lang/Cons.java @@ -31,6 +31,10 @@ public ISeq rest() { return _rest; } +public int count() { + return 1 + RT.count(_rest); +} + public ISeq seq() { return this; } diff --git a/src/jvm/clojure/lang/IPersistentCollection.java b/src/jvm/clojure/lang/IPersistentCollection.java index 0506ba78..d66901d8 100644 --- a/src/jvm/clojure/lang/IPersistentCollection.java +++ b/src/jvm/clojure/lang/IPersistentCollection.java @@ -13,6 +13,7 @@ package clojure.lang; public interface IPersistentCollection {
+int count();
ISeq seq() throws Exception;
}
diff --git a/src/jvm/clojure/lang/IPersistentMap.java b/src/jvm/clojure/lang/IPersistentMap.java index a70af0c2..21158133 100644 --- a/src/jvm/clojure/lang/IPersistentMap.java +++ b/src/jvm/clojure/lang/IPersistentMap.java @@ -11,21 +11,12 @@ package clojure.lang;
-public interface IPersistentMap extends Iterable, IPersistentCollection {
+public interface IPersistentMap extends Iterable, IPersistentCollection, Associative {
-int count();
-
-boolean contains(Object key);
-
-IMapEntry find(Object key);
IPersistentMap add(Object key, Object val) throws Exception;
-IPersistentMap put(Object key, Object val);
-
IPersistentMap remove(Object key);
-Object get(Object key);
-
int capacity();
}
diff --git a/src/jvm/clojure/lang/PersistentArray.java b/src/jvm/clojure/lang/PersistentArray.java index 2f5a5813..154a18a9 100644 --- a/src/jvm/clojure/lang/PersistentArray.java +++ b/src/jvm/clojure/lang/PersistentArray.java @@ -239,6 +239,10 @@ public PersistentArray(IArray init) { data.master.load = load; } +public int count(){ + return data.master.array.length; +} + public int length(){ return data.master.array.length; } diff --git a/src/jvm/clojure/lang/RT.java b/src/jvm/clojure/lang/RT.java index 68f81982..77aa943f 100644 --- a/src/jvm/clojure/lang/RT.java +++ b/src/jvm/clojure/lang/RT.java @@ -386,4 +386,9 @@ static public Object setValues(Object... vals) return null; } +public static int count(Object o) { + if(o == null) + return 0; + return ((IPersistentCollection)o).count(); +} } diff --git a/src/jvm/clojure/lang/Sequential.java b/src/jvm/clojure/lang/Sequential.java new file mode 100644 index 00000000..24417533 --- /dev/null +++ b/src/jvm/clojure/lang/Sequential.java @@ -0,0 +1,13 @@ +package clojure.lang;
+
+/**
+ * Copyright (c) Rich Hickey. All rights reserved.
+ * The use and distribution terms for this software are covered by the
+ * Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
+ * which can be found in the file CPL.TXT 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.
+ */
+public interface Sequential {
+}
diff --git a/src/jvm/clojure/lang/Tuple.java b/src/jvm/clojure/lang/Tuple.java index 41e0048b..479e31bc 100644 --- a/src/jvm/clojure/lang/Tuple.java +++ b/src/jvm/clojure/lang/Tuple.java @@ -26,6 +26,10 @@ public Tuple(Object... init){ this.array = init; } +public int count() { + return array.length; +} + public int length() { return array.length; } |