summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRich Hickey <richhickey@gmail.com>2006-09-30 00:02:23 +0000
committerRich Hickey <richhickey@gmail.com>2006-09-30 00:02:23 +0000
commitbc5dc23be88ad294d86d8d2b09583c41eafdd9b9 (patch)
treecf9ad1d856b4564fd4474be93f509da0be3760b2
parent48c28eff6cff167219f030bca3188219604c9a63 (diff)
added findKey
-rw-r--r--src/cli/runtime/RT.cs15
-rw-r--r--src/jvm/clojure/lang/RT.java15
2 files changed, 30 insertions, 0 deletions
diff --git a/src/cli/runtime/RT.cs b/src/cli/runtime/RT.cs
index 1f97c081..5cf4187f 100644
--- a/src/cli/runtime/RT.cs
+++ b/src/cli/runtime/RT.cs
@@ -196,6 +196,21 @@ static public Object find(Object key, Object coll)
return ((Associative)coll).find(key);
}
+ //takes a seq of key,val,key,val
+//returns tail starting at val of matching key if found, else null
+static public ISeq findKey(Keyword key,ISeq keyvals) {
+ while(keyvals != null)
+ {
+ ISeq r = keyvals.rest();
+ if (r == null)
+ throw new Exception("Malformed keyword argslist");
+ if (keyvals.first() == key)
+ return r;
+ keyvals = r.rest();
+ }
+ return null;
+}
+
static public Object without(Object key, Object coll)
{
if (coll == null)
diff --git a/src/jvm/clojure/lang/RT.java b/src/jvm/clojure/lang/RT.java
index 7fc7b4ab..f00101c0 100644
--- a/src/jvm/clojure/lang/RT.java
+++ b/src/jvm/clojure/lang/RT.java
@@ -180,6 +180,21 @@ static public Object find(Object key, Object coll) {
return ((Associative)coll).find(key);
}
+//takes a seq of key,val,key,val
+//returns tail starting at val of matching key if found, else null
+static public ISeq findKey(Keyword key,ISeq keyvals) throws Exception {
+ while(keyvals != null)
+ {
+ ISeq r = keyvals.rest();
+ if (r == null)
+ throw new Exception("Malformed keyword argslist");
+ if (keyvals.first() == key)
+ return r;
+ keyvals = r.rest();
+ }
+ return null;
+}
+
static public Object without(Object key, Object coll) {
if(coll == null)
return null;