From 7e4123fa20af30ea21b8309d4f354591ed32bc73 Mon Sep 17 00:00:00 2001
From: Christophe Grand <christophe@cgrand.net>
Date: Tue, 13 Apr 2010 14:17:20 +0200
Subject: [PATCH] remove streams

---
 src/clj/clojure/core.clj                    |   11 +--
 src/jvm/clojure/lang/APersistentVector.java |   21 +---
 src/jvm/clojure/lang/ASeq.java              |   26 +----
 src/jvm/clojure/lang/ArrayStream.java       |  184 ---------------------------
 src/jvm/clojure/lang/IteratorStream.java    |   29 ----
 src/jvm/clojure/lang/RT.java                |   26 ----
 src/jvm/clojure/lang/Range.java             |   21 +---
 src/jvm/clojure/lang/Stream.java            |   88 -------------
 src/jvm/clojure/lang/Streamable.java        |   17 ---
 9 files changed, 5 insertions(+), 418 deletions(-)
 delete mode 100644 src/jvm/clojure/lang/ArrayStream.java
 delete mode 100644 src/jvm/clojure/lang/IteratorStream.java
 delete mode 100644 src/jvm/clojure/lang/Stream.java
 delete mode 100644 src/jvm/clojure/lang/Streamable.java

diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj
index a728bc0..cb56ece 100644
--- a/src/clj/clojure/core.clj
+++ b/src/clj/clojure/core.clj
@@ -1804,19 +1804,12 @@
    (fn [& args] (apply f arg1 arg2 arg3 (concat more args)))))
 
 ;;;;;;;;;;;;;;;;;;; sequence fns  ;;;;;;;;;;;;;;;;;;;;;;;
-(defn stream? 
-  "Returns true if x is an instance of Stream"
-  [x] (instance? clojure.lang.Stream x))
-
-
 (defn sequence
   "Coerces coll to a (possibly empty) sequence, if it is not already
   one. Will not force a lazy seq. (sequence nil) yields ()"  
   [coll]
-   (cond 
-    (seq? coll) coll
-    (stream? coll) (.sequence #^clojure.lang.Stream coll)
-    :else (or (seq coll) ())))
+   (if (seq? coll) coll
+    (or (seq coll) ())))
 
 (defn every?
   "Returns true if (pred x) is logical true for every x in coll, else
diff --git a/src/jvm/clojure/lang/APersistentVector.java b/src/jvm/clojure/lang/APersistentVector.java
index 1002351..1761b23 100644
--- a/src/jvm/clojure/lang/APersistentVector.java
+++ b/src/jvm/clojure/lang/APersistentVector.java
@@ -16,7 +16,7 @@ import java.util.*;
 
 public abstract class APersistentVector extends AFn implements IPersistentVector, Iterable,
                                                                List,
-                                                               RandomAccess, Comparable, Streamable{
+                                                               RandomAccess, Comparable{
 int _hash = -1;
 
 public String toString(){
@@ -403,25 +403,6 @@ public int compareTo(Object o){
 	return 0;
 }
 
-public Stream stream() throws Exception {
-    return new Stream(new Src(this));
-}
-
-    static class Src extends AFn{
-        final IPersistentVector v;
-        int i = 0;
-
-        Src(IPersistentVector v) {
-            this.v = v;
-        }
-
-        public Object invoke() throws Exception {
-            if (i < v.count())
-                return v.nth(i++);
-            return RT.EOS;
-        }
-    }
-
     static class Seq extends ASeq implements IndexedSeq, IReduce{
 	//todo - something more efficient
 	final IPersistentVector v;
diff --git a/src/jvm/clojure/lang/ASeq.java b/src/jvm/clojure/lang/ASeq.java
index 73f88da..78e7b6e 100644
--- a/src/jvm/clojure/lang/ASeq.java
+++ b/src/jvm/clojure/lang/ASeq.java
@@ -12,7 +12,7 @@ package clojure.lang;
 
 import java.util.*;
 
-public abstract class ASeq extends Obj implements ISeq, List, Streamable{
+public abstract class ASeq extends Obj implements ISeq, List{
 transient int _hash = -1;
 
 public String toString(){
@@ -204,30 +204,6 @@ public Iterator iterator(){
 
 
 
-public Stream stream() throws Exception {
-    return new Stream(new Src(this));
-}
-
-static class Src extends AFn{
-    ISeq s;
-
-    public Src(ISeq s) {
-        this.s = s;
-    }
-
-	public Object invoke() throws Exception {
-		ISeq sq = RT.seq(s);
-        if(sq != null)
-            {
-            Object ret = sq.first();
-            s = sq.more();
-            return ret;
-            }
-        return RT.EOS;
-    }
-}
-
-
 //////////// List stuff /////////////////
 private List reify(){
 	return Collections.unmodifiableList(new ArrayList(this));
diff --git a/src/jvm/clojure/lang/ArrayStream.java b/src/jvm/clojure/lang/ArrayStream.java
deleted file mode 100644
index 29750ca..0000000
--- a/src/jvm/clojure/lang/ArrayStream.java
+++ /dev/null
@@ -1,184 +0,0 @@
-/**
- *   Copyright (c) Rich Hickey. All rights reserved.
- *   The use and distribution terms for this software are covered by the
- *   Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
- *   which can be found in the file epl-v10.html 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 7, 2008 */
-
-package clojure.lang;
-
-import java.util.concurrent.atomic.AtomicInteger;
-import java.lang.reflect.Array;
-public class ArrayStream extends AFn{
-
-int i = 0;
-final Object[] array;
-
-public ArrayStream(Object[] array){
-	this.array = array;
-}
-
-public Object invoke() throws Exception{
-	if(i < array.length)
-		return array[i++];
-	return RT.EOS;
-}
-
-static Stream createFromObject(Object array){
-	Class aclass = array.getClass().getComponentType();
-	if(!aclass.isPrimitive())
-		return new Stream(new ArrayStream((Object[]) array));
-	if(aclass == int.class)
-		return new Stream(new ArrayStream_int((int[]) array));
-	if(aclass == long.class)
-		return new Stream(new ArrayStream_long((long[]) array));
-	if(aclass == float.class)
-		return new Stream(new ArrayStream_float((float[]) array));
-	if(aclass == double.class)
-		return new Stream(new ArrayStream_double((double[]) array));
-	if(aclass == char.class)
-		return new Stream(new ArrayStream_char((char[]) array));
-	if(aclass == byte.class)
-		return new Stream(new ArrayStream_byte((byte[]) array));
-	if(aclass == short.class)
-		return new Stream(new ArrayStream_short((short[]) array));
-	if(aclass == boolean.class)
-		return new Stream(new ArrayStream_boolean((boolean[]) array));
-	throw new IllegalArgumentException(String.format("Unsupported array type %s", array));
-}
-
-static public class ArrayStream_int extends AFn{
-
-	int i = 0;
-	final int[] array;
-
-	public ArrayStream_int(int[] array){
-		this.array = array;
-	}
-
-	public Object invoke() throws Exception{
-		if(i < array.length)
-			return array[i++];
-		return RT.EOS;
-	}
-}
-
-static public class ArrayStream_long extends AFn{
-
-	int i = 0;
-	final long[] array;
-
-	public ArrayStream_long(long[] array){
-		this.array = array;
-	}
-
-	public Object invoke() throws Exception{
-		if(i < array.length)
-			return array[i++];
-		return RT.EOS;
-	}
-}
-
-static public class ArrayStream_float extends AFn{
-
-	int i = 0;
-	final float[] array;
-
-	public ArrayStream_float(float[] array){
-		this.array = array;
-	}
-
-	public Object invoke() throws Exception{
-		if(i < array.length)
-			return array[i++];
-		return RT.EOS;
-	}
-}
-
-static public class ArrayStream_double extends AFn{
-
-	int i = 0;
-	final double[] array;
-
-	public ArrayStream_double(double[] array){
-		this.array = array;
-	}
-
-	public Object invoke() throws Exception{
-		if(i < array.length)
-			return array[i++];
-		return RT.EOS;
-	}
-}
-
-static public class ArrayStream_char extends AFn{
-
-	int i = 0;
-	final char[] array;
-
-	public ArrayStream_char(char[] array){
-		this.array = array;
-	}
-
-	public Object invoke() throws Exception{
-		if(i < array.length)
-			return array[i++];
-		return RT.EOS;
-	}
-}
-
-static public class ArrayStream_byte extends AFn{
-
-	int i = 0;
-	final byte[] array;
-
-	public ArrayStream_byte(byte[] array){
-		this.array = array;
-	}
-
-	public Object invoke() throws Exception{
-		if(i < array.length)
-			return array[i++];
-		return RT.EOS;
-	}
-}
-
-static public class ArrayStream_short extends AFn{
-
-	int i = 0;
-	final short[] array;
-
-	public ArrayStream_short(short[] array){
-		this.array = array;
-	}
-
-	public Object invoke() throws Exception{
-		if(i < array.length)
-			return array[i++];
-		return RT.EOS;
-	}
-}
-
-static public class ArrayStream_boolean extends AFn{
-
-	int i = 0;
-	final boolean[] array;
-
-	public ArrayStream_boolean(boolean[] array){
-		this.array = array;
-	}
-
-	public Object invoke() throws Exception{
-		if(i < array.length)
-			return array[i++];
-		return RT.EOS;
-	}
-}
-
-
-}
diff --git a/src/jvm/clojure/lang/IteratorStream.java b/src/jvm/clojure/lang/IteratorStream.java
deleted file mode 100644
index 484169b..0000000
--- a/src/jvm/clojure/lang/IteratorStream.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- *   Copyright (c) Rich Hickey. All rights reserved.
- *   The use and distribution terms for this software are covered by the
- *   Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
- *   which can be found in the file epl-v10.html 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 7, 2008 */
-
-package clojure.lang;
-
-import java.util.Iterator;
-
-public class IteratorStream extends AFn{
-final Iterator iter;
-
-IteratorStream(Iterator iter){
-	this.iter = iter;
-}
-
-public Object invoke() throws Exception{
-	if(iter.hasNext())
-		return iter.next();
-	return RT.EOS;
-}
-}
diff --git a/src/jvm/clojure/lang/RT.java b/src/jvm/clojure/lang/RT.java
index 57edb75..2bafcf7 100644
--- a/src/jvm/clojure/lang/RT.java
+++ b/src/jvm/clojure/lang/RT.java
@@ -255,14 +255,6 @@ static public void addURL(Object url) throws Exception{
 		throw new IllegalAccessError("Context classloader is not a DynamicClassLoader");
 }
 
-final static public Object EOS = new Object();
-final static public Object SKIP = new Object();
-static final public IFn EMPTY_GEN = new AFn(){
-    synchronized public Object invoke() throws Exception {
-        return EOS;
-    }
-};
-
 static{
 	Keyword dockw = Keyword.intern(null, "doc");
 	Keyword arglistskw = Keyword.intern(null, "arglists");
@@ -440,24 +432,6 @@ static public ISeq seq(Object coll){
 		return seqFrom(coll);
 }
 
-static public Stream stream(final Object coll) throws Exception{
-	if(coll == null)
-		return new Stream(EMPTY_GEN);
-	else if(coll instanceof Streamable)
-		return ((Streamable) coll).stream();
-	else if(coll instanceof Fn)
-		return new Stream((IFn) coll);
-	else if(coll instanceof Iterable)
-		return new Stream(new IteratorStream(((Iterable) coll).iterator()));
-	else if(coll.getClass().isArray())
-		return ArrayStream.createFromObject(coll);
-	else if(coll instanceof String)
-		return ArrayStream.createFromObject(((String) coll).toCharArray());
-	else
-	    return new Stream(new ASeq.Src(RT.seq(coll)));
-
-}
-
 static ISeq seqFrom(Object coll){
 	if(coll instanceof Seqable)
 		return ((Seqable) coll).seq();
diff --git a/src/jvm/clojure/lang/Range.java b/src/jvm/clojure/lang/Range.java
index 2f0ee42..18a9090 100644
--- a/src/jvm/clojure/lang/Range.java
+++ b/src/jvm/clojure/lang/Range.java
@@ -14,7 +14,7 @@ package clojure.lang;
 
 import java.util.concurrent.atomic.AtomicInteger;
 
-public class Range extends ASeq implements IReduce, Streamable, Counted{
+public class Range extends ASeq implements IReduce, Counted{
 final int end;
 final int n;
 
@@ -63,23 +63,4 @@ public int count() {
     return end - n;
     }
 
-public Stream stream() throws Exception {
-    return new Stream(new Src(n,end));
-}
-
-    static class Src extends AFn{
-        int n;
-        final int end;
-
-        public Src(int n, int end) {
-            this.n = n;
-            this.end = end;
-        }
-
-        public Object invoke() throws Exception {
-            if(n < end)
-                return n++;
-            return RT.EOS;
-        }
-    }
 }
diff --git a/src/jvm/clojure/lang/Stream.java b/src/jvm/clojure/lang/Stream.java
deleted file mode 100644
index 2976a7c..0000000
--- a/src/jvm/clojure/lang/Stream.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/**
- *   Copyright (c) Rich Hickey. All rights reserved.
- *   The use and distribution terms for this software are covered by the
- *   Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
- *   which can be found in the file epl-v10.html 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 5, 2009 */
-
-package clojure.lang;
-
-final public class Stream implements Seqable, Streamable, Sequential {
-
-    static final ISeq NO_SEQ = new Cons(null, null);
-
-    ISeq sequence = NO_SEQ;
-    final IFn src;
-	final IFn xform;
-    IFn tap = null;
-
-	public Stream(IFn src){
-		this.src = src;
-		this.xform = null;
-	}
-
-	public Stream(IFn xform, Stream src) {
-        this.src = src.tap();
-		this.xform = xform;
-    }
-
-	final public ISeq seq(){
-		return sequence().seq();
-	}
-
-	final synchronized public ISeq sequence(){
-		if(sequence == NO_SEQ)
-			{
-			tap();
-			sequence = makeSequence(tap);
-			}
-		return sequence;
-	}
-
-	static ISeq makeSequence(final IFn tap){
-		return new LazySeq(new AFn(){
-				public Object invoke() throws Exception{
-					Object v = tap.invoke();
-					if(v == RT.EOS)
-						return null;
-					return new Cons(v, new LazySeq(this));
-				}
-			});
-	}
-
-    final synchronized public Stream stream() throws Exception {
-            return this;
-    }
-
-    final synchronized public IFn tap() {
-        if (tap != null)
-            throw new IllegalStateException("Stream already tapped");
-
-        return tap = makeTap(xform, src);
-    }
-
-	static IFn makeTap(final IFn xform, final IFn src){
-		return new AFn(){
-			final synchronized public Object invoke() throws Exception{
-				if(xform == null)
-					return src.invoke();
-				Object v;
-				Object xv;
-				do {
-					v = src.invoke();
-					if(v == RT.EOS)
-						return v;
-					xv = xform.invoke(v);
-				} while(xv == RT.SKIP);
-				return xv;
-			}
-		};
-	}
-
-
-}
diff --git a/src/jvm/clojure/lang/Streamable.java b/src/jvm/clojure/lang/Streamable.java
deleted file mode 100644
index 0013554..0000000
--- a/src/jvm/clojure/lang/Streamable.java
+++ /dev/null
@@ -1,17 +0,0 @@
-/**
- *   Copyright (c) Rich Hickey. All rights reserved.
- *   The use and distribution terms for this software are covered by the
- *   Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
- *   which can be found in the file epl-v10.html 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 7, 2008 */
-
-package clojure.lang;
-
-public interface Streamable {
-    Stream stream() throws Exception;
-}
-- 
1.7.0.2.msysgit.0

