Skip to content

Commit 5572d24

Browse files
committed
added IPersistentList, ASeq
1 parent 73f8a47 commit 5572d24

28 files changed

Lines changed: 207 additions & 72 deletions

src/cli/runtime/ASeq.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* Copyright (c) Rich Hickey. All rights reserved.
3+
* The use and distribution terms for this software are covered by the
4+
* Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
5+
* which can be found in the file CPL.TXT at the root of this distribution.
6+
* By using this software in any fashion, you are agreeing to be bound by
7+
* the terms of this license.
8+
* You must not remove this notice, or any other, from this software.
9+
**/
10+
11+
using System;
12+
13+
namespace clojure.lang
14+
{
15+
16+
public abstract class ASeq : ISeq{
17+
18+
public Object peek() {
19+
return first();
20+
}
21+
22+
public IPersistentList pop() {
23+
return rest();
24+
}
25+
26+
public int count() {
27+
return 1 + RT.count(rest());
28+
}
29+
30+
public ISeq seq() {
31+
return this;
32+
}
33+
34+
public IPersistentCollection cons(Object o) {
35+
return new Cons(o, this);
36+
}
37+
38+
#region ISeq Members
39+
40+
abstract public object first();
41+
42+
abstract public ISeq rest();
43+
44+
#endregion
45+
}
46+
47+
}

src/cli/runtime/ArraySeq.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
namespace clojure.lang
1616
{
1717

18-
public class ArraySeq : IndexedSeq{
18+
public class ArraySeq : ASeq, IndexedSeq{
1919
readonly Object[] array;
2020
readonly int i;
2121
ISeq _rest;
@@ -32,11 +32,11 @@ static public ArraySeq create(params Object[] array){
3232
this._rest = this;
3333
}
3434

35-
public Object first() {
35+
override public Object first() {
3636
return array[i];
3737
}
3838

39-
public ISeq rest() {
39+
override public ISeq rest() {
4040
if(_rest == this)
4141
{
4242
if(i+1 < array.Length)

src/cli/runtime/Cons.cs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
namespace clojure.lang
1616
{
1717

18-
public class Cons : ISeq
18+
public class Cons : ASeq
1919
{
2020

2121
private readonly Object _first;
@@ -30,31 +30,18 @@ public Cons(Object first, ISeq rest)
3030

3131
#region ISeq Members
3232

33-
public object first()
33+
override public object first()
3434
{
3535
return _first;
3636
}
3737

38-
public ISeq rest()
38+
override public ISeq rest()
3939
{
4040
return _rest;
4141
}
4242

4343
#endregion
4444

45-
46-
#region IPersistentCollection Members
47-
48-
public ISeq seq()
49-
{
50-
return this;
51-
}
52-
53-
public int count() {
54-
return 1 + RT.count(_rest);
55-
}
56-
57-
#endregion
5845
}
5946

6047
}

src/cli/runtime/EnumeratorSeq.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace clojure.lang
1515
{
16-
public class EnumeratorSeq : ISeq{
16+
public class EnumeratorSeq : ASeq{
1717
IEnumerator e;
1818
volatile ISeq _rest;
1919

@@ -28,11 +28,11 @@ public static EnumeratorSeq create(IEnumerator e){
2828
this._rest = this;
2929
}
3030

31-
public Object first() {
31+
override public Object first() {
3232
return e.Current;
3333
}
3434

35-
public ISeq rest() {
35+
override public ISeq rest() {
3636
if(_rest == this)
3737
{
3838
lock(this){

src/cli/runtime/FnSeq.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
namespace clojure.lang
1414
{
1515

16-
public class FnSeq : ISeq{
16+
public class FnSeq : ASeq{
1717

1818
Object _first;
1919
IFn restFn;
@@ -25,11 +25,11 @@ public FnSeq(Object first, IFn restFn) {
2525
this._rest = this;
2626
}
2727

28-
public Object first() {
28+
override public Object first() {
2929
return _first;
3030
}
3131

32-
public ISeq rest() {
32+
override public ISeq rest() {
3333
if(_rest != this)
3434
return _rest;
3535
lock(this){

src/cli/runtime/IPersistentList.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Copyright (c) Rich Hickey. All rights reserved.
3+
* The use and distribution terms for this software are covered by the
4+
* Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
5+
* which can be found in the file CPL.TXT at the root of this distribution.
6+
* By using this software in any fashion, you are agreeing to be bound by
7+
* the terms of this license.
8+
* You must not remove this notice, or any other, from this software.
9+
*/
10+
11+
using System;
12+
13+
namespace clojure.lang
14+
{
15+
public interface IPersistentList : IPersistentCollection, Sequential {
16+
17+
Object peek();
18+
19+
IPersistentList pop();
20+
21+
}
22+
23+
}

src/cli/runtime/ISeq.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace clojure.lang
1414
{
15-
public interface ISeq
15+
public interface ISeq : IPersistentList
1616
{
1717

1818
Object first();

src/cli/runtime/MapEntry.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,18 @@ override public ISeq seq() {
110110
return new Seq(this);
111111
}
112112

113-
class Seq : ISeq{
113+
class Seq : ASeq{
114114
MapEntry e;
115115

116116
public Seq(MapEntry e) {
117117
this.e = e;
118118
}
119119

120-
public Object first() {
120+
override public Object first() {
121121
return e;
122122
}
123123

124-
public ISeq rest() {
124+
override public ISeq rest() {
125125
return null;
126126
}
127127
}

src/cli/runtime/PersistentArray.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ override internal Entry rest(){
135135
}
136136
}
137137

138-
internal class Seq : IndexedSeq{
138+
internal class Seq : ASeq, IndexedSeq{
139139
readonly PersistentArray p;
140140
readonly int i;
141141

@@ -144,11 +144,11 @@ internal Seq(PersistentArray p, int i){
144144
this.i = i;
145145
}
146146

147-
public Object first() {
147+
override public Object first() {
148148
return p.nth(i);
149149
}
150150

151-
public ISeq rest() {
151+
override public ISeq rest() {
152152
if(i+1 < p.length())
153153
return new Seq(p, i + 1);
154154
return null;

src/cli/runtime/PersistentArrayMap.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ override public ISeq seq() {
182182
return null;
183183
}
184184

185-
internal class Seq : ISeq, IMapEntry{
185+
internal class Seq : ASeq, IMapEntry{
186186
readonly Object[] array;
187187
readonly int i;
188188

@@ -199,11 +199,11 @@ public Object val() {
199199
return array[i+1];
200200
}
201201

202-
public Object first() {
202+
override public Object first() {
203203
return this;
204204
}
205205

206-
public ISeq rest() {
206+
override public ISeq rest() {
207207
if(i+2 < array.Length)
208208
return new Seq(array, i + 2);
209209
return null;

0 commit comments

Comments
 (0)