aboutsummaryrefslogtreecommitdiff
path: root/chunk.d
diff options
context:
space:
mode:
Diffstat (limited to 'chunk.d')
-rw-r--r--chunk.d26
1 files changed, 26 insertions, 0 deletions
diff --git a/chunk.d b/chunk.d
index 08ba003..7a532f5 100644
--- a/chunk.d
+++ b/chunk.d
@@ -46,6 +46,7 @@ abstract class Seq {
abstract Value first();
abstract Seq rest();
abstract int length();
+ abstract Seq concat(Seq seq);
}
class String : Seq {
@@ -53,10 +54,12 @@ class String : Seq {
this(Value value) {
this.str = value.as.str;
+ this.type = SeqType.STRING;
}
this(string str) {
this.str = str;
+ this.type = SeqType.STRING;
}
override Value first() {
@@ -71,6 +74,19 @@ class String : Seq {
return to!int(str.length);
}
+ override Seq concat(Seq seq) {
+ if (seq.type != SeqType.STRING) {
+ // how do i throw an error here?
+ writeln("must concat strings to strings!");
+ return this;
+ }
+ String strSeq = cast(String)seq;
+
+ writefln("in concat with '%s' and '%s'", this.str, strSeq.str);
+
+ return new String(this.str ~ strSeq.str);
+ }
+
override string toString() {
return format("\"%s\"", this.str);
}
@@ -104,6 +120,16 @@ class List : Seq {
return to!int(this.inner.length);
}
+ override Seq concat(Seq seq) {
+ int length = to!int(this.inner.length);
+ List ret = new List(length + 1);
+ for (int i = 0; i < length; i++) {
+ ret.addItemAtIndex(this.inner[i], i);
+ }
+ ret.addItemAtIndex(makeSeqValue(seq), length);
+ return ret;
+ }
+
override string toString() {
return format("list ('%s' + %d)", printableValue(this.inner[0]), this.inner.length - 1);
}