summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRich Hickey <richhickey@gmail.com>2006-06-21 14:19:18 +0000
committerRich Hickey <richhickey@gmail.com>2006-06-21 14:19:18 +0000
commit2833558bb5b06956ac07b0fd7d91b2adb3f188e4 (patch)
treedd5e5921bf46234e930934d4bb2c3e3231314dc7 /src
parent9623392e3ead372e86ab399ac174f6c1a8700379 (diff)
added first,rest, made cons take 2 objects
Diffstat (limited to 'src')
-rw-r--r--src/cli/runtime/RT.cs15
-rw-r--r--src/jvm/clojure/lang/PersistentTree.java22
-rw-r--r--src/jvm/clojure/lang/RT.java87
3 files changed, 64 insertions, 60 deletions
diff --git a/src/cli/runtime/RT.cs b/src/cli/runtime/RT.cs
index be8e85cb..8270a2c9 100644
--- a/src/cli/runtime/RT.cs
+++ b/src/cli/runtime/RT.cs
@@ -174,10 +174,17 @@ static public ISeq seq(Object coll) {
{
return Convert.ToDouble(x);
}
-static public Cons cons(Object x, ISeq y)
- {
- return new Cons(x, y);
- }
+static public Cons cons(Object x, Object y) {
+return new Cons(x, seq(y));
+}
+
+static public Object first(Object x) {
+ return seq(x).first();
+}
+
+static public ISeq rest(Object x) {
+ return seq(x).rest();
+}
static public Cons list()
{
diff --git a/src/jvm/clojure/lang/PersistentTree.java b/src/jvm/clojure/lang/PersistentTree.java
index 75a25e6c..1403ce0c 100644
--- a/src/jvm/clojure/lang/PersistentTree.java
+++ b/src/jvm/clojure/lang/PersistentTree.java
@@ -73,13 +73,13 @@ public PersistentTree remove(Object key){
return new PersistentTree(comp, t.blacken(), _count - 1);
}
-public ISeq seq() {
+public ISeq seq() throws Exception {
if(_count > 0)
return Seq.create(tree, true);
return null;
}
-public ISeq rseq() {
+public ISeq rseq() throws Exception {
if(_count > 0)
return Seq.create(tree, false);
return null;
@@ -615,16 +615,16 @@ static public class Seq implements ISeq{
this.asc = asc;
}
- static Seq create(Node t, boolean asc){
- return new Seq(push(t, null, asc),asc);
- }
+ static Seq create(Node t, boolean asc) throws Exception {
+ return new Seq(push(t, null, asc),asc);
+ }
- static ISeq push(Node t, ISeq stack, boolean asc){
- while(t != null)
- {
- stack = RT.cons(t,stack);
- t = asc ? t.left() : t.right();
- }
+ static ISeq push(Node t, ISeq stack, boolean asc) throws Exception {
+ while(t != null)
+ {
+ stack = RT.cons(t,stack);
+ t = asc ? t.left() : t.right();
+ }
return stack;
}
diff --git a/src/jvm/clojure/lang/RT.java b/src/jvm/clojure/lang/RT.java
index 9347d3a6..da66e970 100644
--- a/src/jvm/clojure/lang/RT.java
+++ b/src/jvm/clojure/lang/RT.java
@@ -187,67 +187,64 @@ static public double doubleCast(Object x)
/******************************************* list support ********************************/
-static public Cons cons(Object x, ISeq y)
- {
- return new Cons(x, y);
- }
+static public Cons cons(Object x, Object y) throws Exception {
+return new Cons(x, seq(y));
+}
+
+static public Object first(Object x) throws Exception {
+ return seq(x).first();
+}
+
+static public ISeq rest(Object x) throws Exception {
+ return seq(x).rest();
+}
static public Cons list()
{
return null;
}
-static public Cons list(Object arg1)
- {
- return cons(arg1, null);
- }
+static public Cons list(Object arg1) throws Exception {
+return cons(arg1, null);
+}
-static public Cons list(Object arg1, Object arg2)
- {
- return listStar(arg1, arg2, null);
- }
+static public Cons list(Object arg1, Object arg2) throws Exception {
+return listStar(arg1, arg2, null);
+}
-static public Cons list(Object arg1, Object arg2, Object arg3)
- {
- return listStar(arg1, arg2, arg3, null);
- }
+static public Cons list(Object arg1, Object arg2, Object arg3) throws Exception {
+return listStar(arg1, arg2, arg3, null);
+}
-static public Cons list(Object arg1, Object arg2, Object arg3, Object arg4)
- {
- return listStar(arg1, arg2, arg3, arg4, null);
- }
+static public Cons list(Object arg1, Object arg2, Object arg3, Object arg4) throws Exception {
+return listStar(arg1, arg2, arg3, arg4, null);
+}
-static public Cons list(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5)
- {
- return listStar(arg1, arg2, arg3, arg4, arg5, null);
- }
+static public Cons list(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) throws Exception {
+return listStar(arg1, arg2, arg3, arg4, arg5, null);
+}
-static public Cons listStar(Object arg1, ISeq rest)
- {
- return cons(arg1, rest);
- }
+static public Cons listStar(Object arg1, ISeq rest) throws Exception {
+return cons(arg1, rest);
+}
-static public Cons listStar(Object arg1, Object arg2, ISeq rest)
- {
- return cons(arg1, cons(arg2, rest));
- }
+static public Cons listStar(Object arg1, Object arg2, ISeq rest) throws Exception {
+return cons(arg1, cons(arg2, rest));
+}
-static public Cons listStar(Object arg1, Object arg2, Object arg3, ISeq rest)
- {
- return cons(arg1, cons(arg2, cons(arg3, rest)));
- }
+static public Cons listStar(Object arg1, Object arg2, Object arg3, ISeq rest) throws Exception {
+return cons(arg1, cons(arg2, cons(arg3, rest)));
+}
-static public Cons listStar(Object arg1, Object arg2, Object arg3, Object arg4, ISeq rest)
- {
- return cons(arg1, cons(arg2, cons(arg3, cons(arg4, rest))));
- }
+static public Cons listStar(Object arg1, Object arg2, Object arg3, Object arg4, ISeq rest) throws Exception {
+return cons(arg1, cons(arg2, cons(arg3, cons(arg4, rest))));
+}
-static public Cons listStar(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, ISeq rest)
- {
- return cons(arg1, cons(arg2, cons(arg3, cons(arg4, cons(arg5, rest)))));
- }
+static public Cons listStar(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, ISeq rest) throws Exception {
+return cons(arg1, cons(arg2, cons(arg3, cons(arg4, cons(arg5, rest)))));
+}
-static public Cons arrayToList(Object[] a){
+static public Cons arrayToList(Object[] a) throws Exception {
Cons ret = null;
for(int i=a.length-1;i>=0;--i)
ret = cons(a[i], ret);