diff options
-rw-r--r-- | src/cli/runtime/AGenerator.cs | 36 | ||||
-rw-r--r-- | src/cli/runtime/Cons.cs | 31 | ||||
-rw-r--r-- | src/cli/runtime/EnumeratorIter.cs | 43 | ||||
-rw-r--r-- | src/cli/runtime/ISeq.cs | 20 | ||||
-rw-r--r-- | src/cli/runtime/Iter.cs | 30 | ||||
-rw-r--r-- | src/cli/runtime/RT.cs | 437 | ||||
-rw-r--r-- | src/org/clojure/runtime/AGenerator.java | 30 | ||||
-rw-r--r-- | src/org/clojure/runtime/Cons.java | 16 | ||||
-rw-r--r-- | src/org/clojure/runtime/ISeq.java | 19 | ||||
-rw-r--r-- | src/org/clojure/runtime/Iter.java | 38 | ||||
-rw-r--r-- | src/org/clojure/runtime/IteratorIter.java | 44 | ||||
-rw-r--r-- | src/org/clojure/runtime/RT.java | 52 |
12 files changed, 567 insertions, 229 deletions
diff --git a/src/cli/runtime/AGenerator.cs b/src/cli/runtime/AGenerator.cs new file mode 100644 index 00000000..3c051e5c --- /dev/null +++ b/src/cli/runtime/AGenerator.cs @@ -0,0 +1,36 @@ +using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace org.clojure.runtime
+ {
+public abstract class AGenerator : ISeq, Iter{
+
+ Object __val;
+ int __state = 0;
+
+
+
+ #region ISeq Members
+
+ public Iter iter()
+ {
+ //generators get 'primed' by calling iterate once, which pulls up to first yield
+ return iterate();
+ }
+
+ #endregion
+
+ #region Iter Members
+
+ public object get()
+ {
+ return __val;
+ }
+
+ abstract public Iter iterate();
+
+
+ #endregion
+ }
+ }
diff --git a/src/cli/runtime/Cons.cs b/src/cli/runtime/Cons.cs index eec4e475..117ad95d 100644 --- a/src/cli/runtime/Cons.cs +++ b/src/cli/runtime/Cons.cs @@ -15,7 +15,7 @@ using System; namespace org.clojure.runtime
{ -public class Cons : AMap
+public class Cons : AMap,Iter,ISeq
{ public Object first; @@ -25,8 +25,31 @@ public Cons(Object first, Cons rest) { this.first = first; this.rest = rest; - } - -} + }
+
+
+#region Iter Members
+
+public object get()
+ {
+ return first;
+ }
+
+public Iter iterate()
+ {
+ return rest;
+ }
+
+#endregion
+
+#region ISeq Members
+
+public Iter iter()
+ {
+ return this;
+ }
+
+#endregion
+ } } diff --git a/src/cli/runtime/EnumeratorIter.cs b/src/cli/runtime/EnumeratorIter.cs new file mode 100644 index 00000000..ccceda93 --- /dev/null +++ b/src/cli/runtime/EnumeratorIter.cs @@ -0,0 +1,43 @@ +/** + * 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;
+using System.Collections;
+
+namespace org.clojure.runtime
+ {
+ internal class EnumeratorIter:Iter
+ {
+ IEnumerator e;
+
+ //presumes that e has already been successfully MovedNext()ed
+ internal EnumeratorIter(IEnumerator e)
+ {
+ this.e = e;
+ }
+
+ #region Iter Members
+
+ public object get()
+ {
+ return e.Current;
+ }
+
+ public Iter iterate()
+ {
+ if (e.MoveNext())
+ return this;
+ return null;
+ }
+
+ #endregion
+ }
+ }
diff --git a/src/cli/runtime/ISeq.cs b/src/cli/runtime/ISeq.cs new file mode 100644 index 00000000..cbde40c9 --- /dev/null +++ b/src/cli/runtime/ISeq.cs @@ -0,0 +1,20 @@ +/** + * 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 org.clojure.runtime
+ {
+ interface ISeq
+ {
+ Iter iter();
+
+ }
+ }
diff --git a/src/cli/runtime/Iter.cs b/src/cli/runtime/Iter.cs new file mode 100644 index 00000000..24c599d4 --- /dev/null +++ b/src/cli/runtime/Iter.cs @@ -0,0 +1,30 @@ +/** + * 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 org.clojure.runtime
+ {
+ public interface Iter
+ {
+/**
+ * * Multiple calls to get() are allowed prior to calling iterate()
+ * * @return the currently referenced item/element/value
+ * */
+ Object get();
+
+ /**
+ * * This may destroy or otherwise invalidate the object it is called upon
+ * * so always capture and use the return value (even though sometimes you may find it is the same object)
+ * * @return The next iter to use, or null if at end of sequence
+ * */
+ Iter iterate();
+ }
+ }
diff --git a/src/cli/runtime/RT.cs b/src/cli/runtime/RT.cs index 777c1299..544cba51 100644 --- a/src/cli/runtime/RT.cs +++ b/src/cli/runtime/RT.cs @@ -1,212 +1,233 @@ -/** - * 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. - **/ - -/* rich Mar 25, 2006 4:28:27 PM */ - +/**
+ * 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.
+ **/
+
+/* rich Mar 25, 2006 4:28:27 PM */
+
using System;
- +using System.Collections;
+
namespace org.clojure.runtime
-{ - +{
+
public class RT
-{ - - static Object TRUE = true; - static public Object eq(Object arg1, Object arg2) { - return (arg1 == arg2)?TRUE:null; - } - - static public Object eql(Object arg1, Object arg2) { - if(arg1 == arg2) - return TRUE; - if(arg1 == null || arg2 == null) - return null; - if(arg1 is Num - && arg1.GetType() == arg2.GetType() - && arg1.Equals(arg2)) - return TRUE; - if(arg1 is Char - && arg2 is Char - && arg1.Equals(arg2)) - return TRUE; - return null; - } - - static public Object equal(Object arg1, Object arg2) { - if(arg1 == null) - return arg2 == null ? TRUE : null; - else if(arg2 == null) - return null; - return (eql(arg1,arg2) != null - || (arg1 is Cons - && arg2 is Cons - && equal(((Cons)arg1).first,((Cons)arg2).first)!=null - && equal(((Cons)arg1).rest,((Cons)arg2).rest)!=null)) - ?TRUE:null; - } - -static public Cons cons(Object x, Cons y) - { - return new Cons(x, y); - } - -static public Cons list() - { - return null; - } - -static public Cons list(Object arg1) - { - 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, Object arg3) - { - 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, Object arg5) - { - return listStar(arg1, arg2, arg3, arg4, arg5, null); - } - -static public Cons listStar(Object arg1, Cons rest) - { - return cons(arg1, rest); - } - -static public Cons listStar(Object arg1, Object arg2, Cons rest) - { - return cons(arg1, cons(arg2, rest)); - } - -static public Cons listStar(Object arg1, Object arg2, Object arg3, Cons rest) - { - return cons(arg1, cons(arg2, cons(arg3, rest))); - } - -static public Cons listStar(Object arg1, Object arg2, Object arg3, Object arg4, Cons rest) - { - return cons(arg1, cons(arg2, cons(arg3, cons(arg4, rest)))); - } - -static public Cons listStar(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Cons rest) - { - return cons(arg1, cons(arg2, cons(arg3, cons(arg4, cons(arg5, rest))))); - } - -static public int length(Cons list) - { - int i = 0; - for(Cons c = list; c != null; c = c.rest) - { - i++; - } - return i; - } - -static public int boundedLength(Cons list, int limit) - { - int i = 0; - for(Cons c = list; c != null && i <= limit; c = c.rest) - { - i++; - } - return i; - } - -static public Object setValues(ThreadLocalData tld, Object arg1) - { - if(tld == null) - tld = ThreadLocalData.get(); - tld.mvCount = 1; - tld.mvArray[0] = arg1; - return arg1; - } - -static public Object setValues(ThreadLocalData tld, Object arg1, Object arg2) - { - if(tld == null) - tld = ThreadLocalData.get(); - tld.mvCount = 2; - tld.mvArray[0] = arg1; - tld.mvArray[1] = arg2; - return arg1; - } - -static public Object setValues(ThreadLocalData tld, Object arg1, Object arg2, Object arg3) - { - if(tld == null) - tld = ThreadLocalData.get(); - tld.mvCount = 3; - tld.mvArray[0] = arg1; - tld.mvArray[1] = arg2; - tld.mvArray[2] = arg3; - return arg1; - } - -static public Object setValues(ThreadLocalData tld, Object arg1, Object arg2, Object arg3, Object arg4) - { - if(tld == null) - tld = ThreadLocalData.get(); - tld.mvCount = 4; - tld.mvArray[0] = arg1; - tld.mvArray[1] = arg2; - tld.mvArray[2] = arg3; - tld.mvArray[3] = arg4; - return arg1; - } - -static public Object setValues(ThreadLocalData tld, Object arg1, Object arg2, Object arg3, Object arg4, - Object arg5) - { - if(tld == null) - tld = ThreadLocalData.get(); - tld.mvCount = 5; - tld.mvArray[0] = arg1; - tld.mvArray[1] = arg2; - tld.mvArray[2] = arg3; - tld.mvArray[3] = arg4; - tld.mvArray[4] = arg5; - return arg1; - } - -static public Object setValues(ThreadLocalData tld, Object arg1, Object arg2, Object arg3, Object arg4, - Object arg5, Cons args) /*throws Exception*/ - { - if(tld == null) - tld = ThreadLocalData.get(); - tld.mvCount = 5; - tld.mvArray[0] = arg1; - tld.mvArray[1] = arg2; - tld.mvArray[2] = arg3; - tld.mvArray[3] = arg4; - tld.mvArray[4] = arg5; - for(int i = 5; args != null && i < ThreadLocalData.MULTIPLE_VALUES_LIMIT; i++, args = args.rest) - { - tld.mvArray[i] = args.first; - } - if(args != null) - throw new ArgumentException("Too many arguments to values (> ThreadLocalData.MULTIPLE_VALUES_LIMIT)"); - return arg1; - } - -} +{
+
+ static Object TRUE = true;
+ static public Object eq(Object arg1, Object arg2) {
+ return (arg1 == arg2)?TRUE:null;
+ }
+
+ static public Object eql(Object arg1, Object arg2) {
+ if(arg1 == arg2)
+ return TRUE;
+ if(arg1 == null || arg2 == null)
+ return null;
+ if(arg1 is Num
+ && arg1.GetType() == arg2.GetType()
+ && arg1.Equals(arg2))
+ return TRUE;
+ if(arg1 is Char
+ && arg2 is Char
+ && arg1.Equals(arg2))
+ return TRUE;
+ return null;
+ }
+
+ static public Object equal(Object arg1, Object arg2) {
+ if(arg1 == null)
+ return arg2 == null ? TRUE : null;
+ else if(arg2 == null)
+ return null;
+ return (eql(arg1,arg2) != null
+ || (arg1 is Cons
+ && arg2 is Cons
+ && equal(((Cons)arg1).first,((Cons)arg2).first)!=null
+ && equal(((Cons)arg1).rest,((Cons)arg2).rest)!=null))
+ ?TRUE:null;
+ }
+
+ static public Iter iter(Object coll)
+ {
+ if (coll == null)
+ return null;
+ else if (coll is ISeq)
+ return ((ISeq)coll).iter();
+ else if (coll is IEnumerable)
+ {
+ IEnumerator e = ((IEnumerable)coll).GetEnumerator();
+ if (e.MoveNext())
+ return new EnumeratorIter(e);
+ return null;
+ }
+ else
+ {
+ throw new ArgumentException("Don't know how to create Iter from arg");
+ }
+
+ }
+
+static public Cons cons(Object x, Cons y)
+ {
+ return new Cons(x, y);
+ }
+
+static public Cons list()
+ {
+ return null;
+ }
+
+static public Cons list(Object arg1)
+ {
+ 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, Object arg3)
+ {
+ 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, Object arg5)
+ {
+ return listStar(arg1, arg2, arg3, arg4, arg5, null);
+ }
+
+static public Cons listStar(Object arg1, Cons rest)
+ {
+ return cons(arg1, rest);
+ }
+
+static public Cons listStar(Object arg1, Object arg2, Cons rest)
+ {
+ return cons(arg1, cons(arg2, rest));
+ }
+
+static public Cons listStar(Object arg1, Object arg2, Object arg3, Cons rest)
+ {
+ return cons(arg1, cons(arg2, cons(arg3, rest)));
+ }
+
+static public Cons listStar(Object arg1, Object arg2, Object arg3, Object arg4, Cons rest)
+ {
+ return cons(arg1, cons(arg2, cons(arg3, cons(arg4, rest))));
+ }
+
+static public Cons listStar(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Cons rest)
+ {
+ return cons(arg1, cons(arg2, cons(arg3, cons(arg4, cons(arg5, rest)))));
+ }
+
+static public int length(Cons list)
+ {
+ int i = 0;
+ for(Cons c = list; c != null; c = c.rest)
+ {
+ i++;
+ }
+ return i;
+ }
+
+static public int boundedLength(Cons list, int limit)
+ {
+ int i = 0;
+ for(Cons c = list; c != null && i <= limit; c = c.rest)
+ {
+ i++;
+ }
+ return i;
+ }
+
+static public Object setValues(ThreadLocalData tld, Object arg1)
+ {
+ if(tld == null)
+ tld = ThreadLocalData.get();
+ tld.mvCount = 1;
+ tld.mvArray[0] = arg1;
+ return arg1;
+ }
+
+static public Object setValues(ThreadLocalData tld, Object arg1, Object arg2)
+ {
+ if(tld == null)
+ tld = ThreadLocalData.get();
+ tld.mvCount = 2;
+ tld.mvArray[0] = arg1;
+ tld.mvArray[1] = arg2;
+ return arg1;
+ }
+
+static public Object setValues(ThreadLocalData tld, Object arg1, Object arg2, Object arg3)
+ {
+ if(tld == null)
+ tld = ThreadLocalData.get();
+ tld.mvCount = 3;
+ tld.mvArray[0] = arg1;
+ tld.mvArray[1] = arg2;
+ tld.mvArray[2] = arg3;
+ return arg1;
+ }
+
+static public Object setValues(ThreadLocalData tld, Object arg1, Object arg2, Object arg3, Object arg4)
+ {
+ if(tld == null)
+ tld = ThreadLocalData.get();
+ tld.mvCount = 4;
+ tld.mvArray[0] = arg1;
+ tld.mvArray[1] = arg2;
+ tld.mvArray[2] = arg3;
+ tld.mvArray[3] = arg4;
+ return arg1;
+ }
+
+static public Object setValues(ThreadLocalData tld, Object arg1, Object arg2, Object arg3, Object arg4,
+ Object arg5)
+ {
+ if(tld == null)
+ tld = ThreadLocalData.get();
+ tld.mvCount = 5;
+ tld.mvArray[0] = arg1;
+ tld.mvArray[1] = arg2;
+ tld.mvArray[2] = arg3;
+ tld.mvArray[3] = arg4;
+ tld.mvArray[4] = arg5;
+ return arg1;
+ }
+
+static public Object setValues(ThreadLocalData tld, Object arg1, Object arg2, Object arg3, Object arg4,
+ Object arg5, Cons args) /*throws Exception*/
+ {
+ if(tld == null)
+ tld = ThreadLocalData.get();
+ tld.mvCount = 5;
+ tld.mvArray[0] = arg1;
+ tld.mvArray[1] = arg2;
+ tld.mvArray[2] = arg3;
+ tld.mvArray[3] = arg4;
+ tld.mvArray[4] = arg5;
+ for(int i = 5; args != null && i < ThreadLocalData.MULTIPLE_VALUES_LIMIT; i++, args = args.rest)
+ {
+ tld.mvArray[i] = args.first;
+ }
+ if(args != null)
+ throw new ArgumentException("Too many arguments to values (> ThreadLocalData.MULTIPLE_VALUES_LIMIT)");
+ return arg1;
+ }
+
+}
}
\ No newline at end of file diff --git a/src/org/clojure/runtime/AGenerator.java b/src/org/clojure/runtime/AGenerator.java new file mode 100644 index 00000000..c6d2875d --- /dev/null +++ b/src/org/clojure/runtime/AGenerator.java @@ -0,0 +1,30 @@ +/** + * 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. + **/ + +/* rich Apr 3, 2006 */ + +package org.clojure.runtime; + +public abstract class AGenerator implements ISeq, Iter{ + +Object __val; +int __state = 0; + +public Object get() + { + return __val; + } + +public Iter iter() + { + //generators get 'primed' by calling iterate once, which pulls up to first yield + return iterate(); + } +} diff --git a/src/org/clojure/runtime/Cons.java b/src/org/clojure/runtime/Cons.java index 22980e74..6d19f019 100644 --- a/src/org/clojure/runtime/Cons.java +++ b/src/org/clojure/runtime/Cons.java @@ -12,7 +12,7 @@ package org.clojure.runtime; -public class Cons extends AMap{ +public class Cons extends AMap implements Iter, ISeq{ public Object first; public Cons rest; @@ -23,4 +23,18 @@ public Cons(Object first, Cons rest) this.rest = rest; } +public Object get() + { + return first; + } + +public Iter iterate() + { + return rest; + } + +public Iter iter() + { + return this; + } } diff --git a/src/org/clojure/runtime/ISeq.java b/src/org/clojure/runtime/ISeq.java new file mode 100644 index 00000000..e5d4c8fa --- /dev/null +++ b/src/org/clojure/runtime/ISeq.java @@ -0,0 +1,19 @@ +/** + * 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. + **/ + +/* rich Apr 3, 2006 */ + +package org.clojure.runtime; + +public interface ISeq{ + +public Iter iter(); + +} diff --git a/src/org/clojure/runtime/Iter.java b/src/org/clojure/runtime/Iter.java new file mode 100644 index 00000000..82e1db5a --- /dev/null +++ b/src/org/clojure/runtime/Iter.java @@ -0,0 +1,38 @@ +/** + * 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. + **/ + +/* rich Apr 3, 2006 10:54:14 AM */ + +package org.clojure.runtime; + + +/** + * Implements a sequential iteration protocol + * <pre> + * for(Iter i = getAnIter();i!=null;i = i.iterate()) + * { + * //use i.get() + * } + * </pre> + */ +public interface Iter{ +/** + * Multiple calls to get() are allowed prior to calling iterate() + * @return the currently referenced item/element/value + */ +public Object get(); + +/** + * This may destroy or otherwise invalidate the object it is called upon + * so always capture and use the return value (even though sometimes you may find it is the same object) + * @return The next iter to use, or null if at end of sequence + */ +public Iter iterate(); +} diff --git a/src/org/clojure/runtime/IteratorIter.java b/src/org/clojure/runtime/IteratorIter.java new file mode 100644 index 00000000..bfcec41a --- /dev/null +++ b/src/org/clojure/runtime/IteratorIter.java @@ -0,0 +1,44 @@ +/** + * 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. + **/ + +/* rich Apr 3, 2006 */ + +package org.clojure.runtime; + +import java.util.Iterator; + +public class IteratorIter implements Iter{ + +Iterator i; +Object val; + +IteratorIter(Iterator i) + { + if(!i.hasNext()) + throw new IllegalStateException("Iterator must have elements to construct Iter"); + this.i = i; + val = i.next(); + } + +public Object get() + { + return val; + } + +public Iter iterate() + { + if(i.hasNext()) + { + val = i.next(); + return this; + } + return null; + } +} diff --git a/src/org/clojure/runtime/RT.java b/src/org/clojure/runtime/RT.java index 4ecabb82..ca49f32f 100644 --- a/src/org/clojure/runtime/RT.java +++ b/src/org/clojure/runtime/RT.java @@ -12,6 +12,8 @@ package org.clojure.runtime; +import java.util.Iterator; + public class RT{ static public Object eq(Object arg1, Object arg2) { @@ -20,32 +22,50 @@ public class RT{ static public Object eql(Object arg1, Object arg2) { if(arg1 == arg2) - return Boolean.TRUE; + return Boolean.TRUE; if(arg1 == null || arg2 == null) - return null; + return null; if(arg1 instanceof Num - && arg1.getClass() == arg2.getClass() - && arg1.equals(arg2)) - return Boolean.TRUE; + && arg1.getClass() == arg2.getClass() + && arg1.equals(arg2)) + return Boolean.TRUE; if(arg1.getClass() == Character.class - && arg2.getClass() == Character.class - && arg1.equals(arg2)) - return Boolean.TRUE; + && arg2.getClass() == Character.class + && arg1.equals(arg2)) + return Boolean.TRUE; return null; } static public Object equal(Object arg1, Object arg2) { if(arg1 == null) - return arg2 == null ? Boolean.TRUE : null; + return arg2 == null ? Boolean.TRUE : null; else if(arg2 == null) return null; - return (eql(arg1,arg2) != null - || (arg1.getClass() == Cons.class - && arg2.getClass() == Cons.class - && equal(((Cons)arg1).first,((Cons)arg2).first)!=null - && equal(((Cons)arg1).rest,((Cons)arg2).rest)!=null)) - ?Boolean.TRUE:null; - } + return (eql(arg1,arg2) != null + || (arg1.getClass() == Cons.class + && arg2.getClass() == Cons.class + && equal(((Cons)arg1).first,((Cons)arg2).first)!=null + && equal(((Cons)arg1).rest,((Cons)arg2).rest)!=null)) + ?Boolean.TRUE:null; + } + +static public Iter iter(Object coll) + { + if(coll == null) + return null; + else if(coll instanceof ISeq) + return ((ISeq) coll).iter(); + else if(coll instanceof Iterator) + { + Iterator i = (Iterator) coll; + if(i.hasNext()) + return new IteratorIter(i); + return null; + } + else + throw new IllegalArgumentException("Don't know how to create Iter from arg"); + } + static public Cons cons(Object x, Cons y) { |