diff options
Diffstat (limited to 'chunk.d')
| -rw-r--r-- | chunk.d | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -47,6 +47,7 @@ abstract class Seq { abstract Seq rest(); abstract int length(); abstract Seq concat(Seq seq); + abstract bool isIn(Value val); } class String : Seq { @@ -87,6 +88,22 @@ class String : Seq { return new String(this.str ~ strSeq.str); } + override bool isIn(Value val) { + if (val.type != ValueType.SEQ) { + // how do i throw an error here? + writeln("a non-string can't be 'in?' a string (this should be a compile error)"); + return false; + } + Seq seq = val.as.seq; + if (seq.type != SeqType.STRING) { + // how do i throw an error here? + writeln("a non-string can't be 'in?' a string (this should be a compile error)"); + return false; + } + String strVal = cast(String)seq; + return (indexOf(this.str, strVal.str) != -1); + } + override string toString() { return format("\"%s\"", this.str); } @@ -130,6 +147,15 @@ class List : Seq { return ret; } + override bool isIn(Value val) { + foreach(Value mine ; this.inner) { + if (areValuesEqual(mine, val)) { + return true; + } + } + return false; + } + override string toString() { return format("list ('%s' + %d)", printableValue(this.inner[0]), this.inner.length - 1); } @@ -169,6 +195,7 @@ enum OpCode { OP_FIRST, // No? OP_REST, OP_LENGTH, + OP_MEMBER, OP_TYPE_CHECK_NUMBER, OP_TYPE_CHECK_BOOLEAN, |
