From ac3c1ae28a18395a15b8a4f85ea2ad90a3e9e540 Mon Sep 17 00:00:00 2001 From: Rich Hickey Date: Wed, 9 Aug 2006 13:27:47 +0000 Subject: removed chaining from ArraySeq.rest, changed meta handling in queue --- src/cli/runtime/ArraySeq.cs | 22 +++++++++++++--------- src/cli/runtime/PersistentQueue.cs | 20 +++++++++----------- 2 files changed, 22 insertions(+), 20 deletions(-) (limited to 'src/cli') diff --git a/src/cli/runtime/ArraySeq.cs b/src/cli/runtime/ArraySeq.cs index c2c56da7..144d872f 100644 --- a/src/cli/runtime/ArraySeq.cs +++ b/src/cli/runtime/ArraySeq.cs @@ -18,7 +18,7 @@ namespace clojure.lang public class ArraySeq : ASeq, IndexedSeq{ readonly Object[] array; readonly int i; -ISeq _rest; +//ISeq _rest; static public ArraySeq create(params Object[] array){ if(array.Length == 0) @@ -29,7 +29,7 @@ static public ArraySeq create(params Object[] array){ ArraySeq(Object[] array, int i){ this.array = array; this.i = i; - this._rest = this; +// this._rest = this; } override public Object first() { @@ -37,13 +37,17 @@ override public Object first() { } override public ISeq rest() { - if(_rest == this) - { - if(i+1 < array.Length) - _rest = new ArraySeq(array, i + 1); - _rest = null; - } - return _rest; + if (i + 1 < array.Length) + return new ArraySeq(array, i + 1); + return null; + +// if(_rest == this) +// { +// if(i+1 < array.Length) +// _rest = new ArraySeq(array, i + 1); +// _rest = null; +// } +// return _rest; } public int index(){ diff --git a/src/cli/runtime/PersistentQueue.cs b/src/cli/runtime/PersistentQueue.cs index 3069dfd1..77b72035 100644 --- a/src/cli/runtime/PersistentQueue.cs +++ b/src/cli/runtime/PersistentQueue.cs @@ -23,16 +23,17 @@ namespace clojure.lang public class PersistentQueue : Obj, IPersistentList { -readonly public static PersistentQueue EMPTY = new PersistentQueue(null,null); +readonly public static PersistentQueue EMPTY = new PersistentQueue(null,null,null); readonly ISeq f; readonly PersistentArrayList r; static readonly int INITIAL_REAR_SIZE = 4; -PersistentQueue(ISeq f, PersistentArrayList r) { +PersistentQueue(ISeq f, PersistentArrayList r, IPersistentMap meta) { this.f = f; this.r = r; + this._meta = meta; } public Object peek() { @@ -50,9 +51,7 @@ public IPersistentList pop() { f1 = RT.seq(r); r1 = null; } - PersistentQueue ret = new PersistentQueue(f1, r1); - ret._meta = _meta; - return ret; + return new PersistentQueue(f1, r1,_meta); } public int count() { @@ -68,12 +67,11 @@ public ISeq seq() { public IPersistentCollection cons(Object o) { PersistentQueue ret; if(f == null) //empty - ret = new PersistentQueue(RT.list(o), null); + return new PersistentQueue(RT.list(o), null,_meta); else - ret= new PersistentQueue(f, - (PersistentArrayList) (r != null ? r : new PersistentArrayList(INITIAL_REAR_SIZE)).cons(o)); - ret._meta = _meta; - return ret; + return new PersistentQueue(f, + (PersistentArrayList) (r != null ? r : new PersistentArrayList(INITIAL_REAR_SIZE)).cons(o), + _meta); } public override Obj withMeta(IPersistentMap meta) @@ -112,7 +110,7 @@ class Seq : ASeq { } } -/* +//* public static void Main(String[] args) { if (args.Length != 1) { -- cgit v1.2.3-70-g09d2