summaryrefslogtreecommitdiff
path: root/src/jvm
diff options
context:
space:
mode:
Diffstat (limited to 'src/jvm')
-rw-r--r--src/jvm/clojure/lang/RT.java2
-rw-r--r--src/jvm/clojure/lang/StringSeq.java50
2 files changed, 52 insertions, 0 deletions
diff --git a/src/jvm/clojure/lang/RT.java b/src/jvm/clojure/lang/RT.java
index 30af3c4b..b2e1b16f 100644
--- a/src/jvm/clojure/lang/RT.java
+++ b/src/jvm/clojure/lang/RT.java
@@ -232,6 +232,8 @@ static public ISeq seq(Object coll){
return IteratorSeq.create(((Iterable) coll).iterator());
else if(coll instanceof Object[])
return ArraySeq.create((Object[]) coll);
+ else if(coll instanceof String)
+ return StringSeq.create((String) coll);
else
throw new IllegalAccessError("Don't know how to create ISeq from arg");
}
diff --git a/src/jvm/clojure/lang/StringSeq.java b/src/jvm/clojure/lang/StringSeq.java
new file mode 100644
index 00000000..c6d8c2b5
--- /dev/null
+++ b/src/jvm/clojure/lang/StringSeq.java
@@ -0,0 +1,50 @@
+/**
+ * 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 Dec 6, 2007 */
+
+package clojure.lang;
+
+public class StringSeq extends ASeq implements IndexedSeq{
+final String s;
+final int i;
+
+static public StringSeq create(String s){
+ if(s.length() == 0)
+ return null;
+ return new StringSeq(null, s, 0);
+}
+
+StringSeq(IPersistentMap meta, String s, int i){
+ super(meta);
+ this.s = s;
+ this.i = i;
+}
+
+public Obj withMeta(IPersistentMap meta){
+ if(meta == meta())
+ return this;
+ return new StringSeq(meta, s, i);
+}
+
+public Object first(){
+ return Character.valueOf(s.charAt(i));
+}
+
+public ISeq rest(){
+ if(i + 1 < s.length())
+ return new StringSeq(_meta, s, i + 1);
+ return null;
+}
+
+public int index(){
+ return i;
+}
+}