Implement state unset

This commit is contained in:
Araozu 2024-05-19 23:11:23 -05:00
parent ea7889726c
commit e52ce64bce
2 changed files with 11 additions and 3 deletions

View File

@ -138,7 +138,7 @@ const codeHtml = highlightCode(trimAndDedent(code));
</div> </div>
<script> <script>
type Instruction = "line" | "out" | "set"; type Instruction = "line" | "out" | "set" | "unset";
type AlpineState = { type AlpineState = {
line: number, line: number,
stdout: string, stdout: string,
@ -170,6 +170,10 @@ const codeHtml = highlightCode(trimAndDedent(code));
data.state[String(instructionArr[1])] = String(instructionArr[2]); data.state[String(instructionArr[1])] = String(instructionArr[2]);
break; break;
} }
case "unset": {
delete data.state[String(instructionArr[1])];
break;
}
} }
} }

View File

@ -86,17 +86,21 @@ Use a naked `try` when you want to rethrow an error, if there is any.
steps={`[ steps={`[
[["line", 14]], [["line", 14]],
[["line", 7]], [["line", 7]],
[["line", 10]], [
["line", 10],
["set", "Int result", "..."]
],
[["line", 1]], [["line", 1]],
[["line", 3]], [["line", 3]],
[ [
["line", 10], ["line", 10],
["set", "result", 50] ["set", "Int result", "Int 50"]
], ],
[["line", 11]], [["line", 11]],
[ [
["line", 14], ["line", 14],
["out", "The result is 50\\n"], ["out", "The result is 50\\n"],
["unset", "Int result"],
], ],
[ [
["line", 15], ["line", 15],