diff options
| author | mryouse | 2023-06-06 19:45:47 -0400 |
|---|---|---|
| committer | mryouse | 2023-06-06 19:45:47 -0400 |
| commit | 87ee44163d0f7ec86963cefea51e721ce4eb156c (patch) | |
| tree | 7f3ef821f7ee1437b1df5558255f37d00bb6198e /chunk.d | |
| parent | 7393da674216aa3dd737db7ec4a3418ca025871c (diff) | |
initial commit of most and last
Diffstat (limited to 'chunk.d')
| -rw-r--r-- | chunk.d | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -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 |
