diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/clj/clojure/core.clj | 11 | ||||
-rw-r--r-- | src/clj/clojure/gvec.clj | 1 | ||||
-rw-r--r-- | src/jvm/clojure/lang/APersistentMap.java | 1 | ||||
-rw-r--r-- | src/jvm/clojure/lang/APersistentSet.java | 1 | ||||
-rw-r--r-- | src/jvm/clojure/lang/APersistentVector.java | 22 | ||||
-rw-r--r-- | src/jvm/clojure/lang/ASeq.java | 28 | ||||
-rw-r--r-- | src/jvm/clojure/lang/ArrayStream.java | 184 | ||||
-rw-r--r-- | src/jvm/clojure/lang/Compiler.java | 3 | ||||
-rw-r--r-- | src/jvm/clojure/lang/IteratorStream.java | 29 | ||||
-rw-r--r-- | src/jvm/clojure/lang/Numbers.java | 2 | ||||
-rw-r--r-- | src/jvm/clojure/lang/RT.java | 26 | ||||
-rw-r--r-- | src/jvm/clojure/lang/Range.java | 21 | ||||
-rw-r--r-- | src/jvm/clojure/lang/Stream.java | 88 | ||||
-rw-r--r-- | src/jvm/clojure/lang/Streamable.java | 17 |
14 files changed, 14 insertions, 420 deletions
diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj index b4e111a1..06ca970b 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/clj/clojure/gvec.clj b/src/clj/clojure/gvec.clj index a47959b0..2b1223ad 100644 --- a/src/clj/clojure/gvec.clj +++ b/src/clj/clojure/gvec.clj @@ -84,6 +84,7 @@ Object (equals [this o] (cond + (identical? this o) true (or (instance? clojure.lang.IPersistentVector o) (instance? java.util.RandomAccess o)) (and (= cnt (count o)) (loop [i (int 0)] diff --git a/src/jvm/clojure/lang/APersistentMap.java b/src/jvm/clojure/lang/APersistentMap.java index e693a802..213eef71 100644 --- a/src/jvm/clojure/lang/APersistentMap.java +++ b/src/jvm/clojure/lang/APersistentMap.java @@ -44,6 +44,7 @@ public IPersistentCollection cons(Object o){ }
public boolean equals(Object obj){
+ if(this == obj) return true;
if(!(obj instanceof Map))
return false;
Map m = (Map) obj;
diff --git a/src/jvm/clojure/lang/APersistentSet.java b/src/jvm/clojure/lang/APersistentSet.java index 988ff5dd..90275fcd 100644 --- a/src/jvm/clojure/lang/APersistentSet.java +++ b/src/jvm/clojure/lang/APersistentSet.java @@ -49,6 +49,7 @@ public Object invoke(Object arg1) throws Exception{ } public boolean equals(Object obj){ + if(this == obj) return true; if(!(obj instanceof Set)) return false; Set m = (Set) obj; diff --git a/src/jvm/clojure/lang/APersistentVector.java b/src/jvm/clojure/lang/APersistentVector.java index 10023512..7ac9f32b 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(){ @@ -36,6 +36,7 @@ public ISeq rseq(){ } static boolean doEquals(IPersistentVector v, Object obj){ + if(v == obj) return true; if(obj instanceof List || obj instanceof IPersistentVector) { Collection ma = (Collection) obj; @@ -403,25 +404,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 73f88da7..ffa7fa47 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(){
@@ -46,7 +46,7 @@ public boolean equiv(Object obj){ }
public boolean equals(Object obj){
-
+ if(this == obj) return true;
if(!(obj instanceof Sequential || obj instanceof List))
return false;
ISeq ms = RT.seq(obj);
@@ -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 29750cad..00000000 --- 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/Compiler.java b/src/jvm/clojure/lang/Compiler.java index f7dc63cc..dc918e04 100644 --- a/src/jvm/clojure/lang/Compiler.java +++ b/src/jvm/clojure/lang/Compiler.java @@ -5621,7 +5621,8 @@ static public Object maybeResolveIn(Namespace n, Symbol sym) throws Exception{ return null; return v; } - else if(sym.name.indexOf('.') > 0 || sym.name.charAt(0) == '[') + else if(sym.name.indexOf('.') > 0 && !sym.name.endsWith(".") + || sym.name.charAt(0) == '[') { return RT.classForName(sym.name); } diff --git a/src/jvm/clojure/lang/IteratorStream.java b/src/jvm/clojure/lang/IteratorStream.java deleted file mode 100644 index 484169b2..00000000 --- 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/Numbers.java b/src/jvm/clojure/lang/Numbers.java index 09dc050b..bd4a5150 100644 --- a/src/jvm/clojure/lang/Numbers.java +++ b/src/jvm/clojure/lang/Numbers.java @@ -295,6 +295,8 @@ static public Number divide(BigInteger n, BigInteger d){ d = d.divide(gcd); if(d.equals(BigInteger.ONE)) return reduce(n); + else if(d.equals(BigInteger.ONE.negate())) + return reduce(n.negate()); return new Ratio((d.signum() < 0 ? n.negate() : n), (d.signum() < 0 ? d.negate() : d)); } diff --git a/src/jvm/clojure/lang/RT.java b/src/jvm/clojure/lang/RT.java index cabe8a7a..8faf011e 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 2f0ee42a..18a90901 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 2976a7c6..00000000 --- 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 00135547..00000000 --- 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; -} |