aboutsummaryrefslogtreecommitdiff
path: root/chunk.d
diff options
context:
space:
mode:
authormryouse2023-05-26 03:15:51 +0000
committermryouse2023-05-26 03:15:51 +0000
commit2ffc9959f3324a234d8337f05643c8e531154081 (patch)
tree70d8b066adc8e72c5c64e4eb71da68ced0ccd00d /chunk.d
parentaab6510a0e59c26a31526ff303a9d581736815fc (diff)
in? (lists and strings)
Diffstat (limited to 'chunk.d')
-rw-r--r--chunk.d27
1 files changed, 27 insertions, 0 deletions
diff --git a/chunk.d b/chunk.d
index 68df45b..b6a5348 100644
--- a/chunk.d
+++ b/chunk.d
@@ -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,