aboutsummaryrefslogtreecommitdiff
path: root/chunk.d
diff options
context:
space:
mode:
Diffstat (limited to 'chunk.d')
-rw-r--r--chunk.d28
1 files changed, 28 insertions, 0 deletions
diff --git a/chunk.d b/chunk.d
index 55772dc..21ebb9d 100644
--- a/chunk.d
+++ b/chunk.d
@@ -45,6 +45,8 @@ abstract class Seq {
SeqType type;
abstract Value first();
abstract Seq rest();
+ abstract Seq most();
+ abstract Value last();
abstract int length();
abstract bool isIn(Value val);
}
@@ -70,6 +72,14 @@ class String : Seq {
return new String(this.str[1..$]);
}
+ override Seq most() {
+ return new String(this.str[0..$ - 1]);
+ }
+
+ override Value last() {
+ return makeStringValue(to!string(this.str[$ - 1]));
+ }
+
override int length() {
return to!int(str.length);
}
@@ -133,6 +143,22 @@ class List : Seq {
return ret;
}
+ override Seq most() {
+ if (this.inner.length == 0) {
+ return new List(0);
+ }
+ int newLength = to!int(this.inner.length) - 1;
+ List ret = new List(newLength);
+ for (int i = 0; i < newLength; i++) {
+ ret.addItemAtIndex(this.inner[i], i);
+ }
+ return ret;
+ }
+
+ override Value last() {
+ return this.inner[$ - 1]; // this fails on NIL
+ }
+
override int length() {
return to!int(this.inner.length);
}
@@ -195,7 +221,9 @@ enum OpCode {
OP_APPEND,
OP_FIRST, // No?
OP_LENGTH,
+ OP_LAST,
OP_MEMBER,
+ OP_MOST,
OP_REST,
// DEFINITIONS/VARIABLES