Compare commits

...

2 Commits

Author SHA1 Message Date
c7b429105d Add more detailed interactive code 2024-05-19 23:40:31 -05:00
e52ce64bce Implement state unset 2024-05-19 23:11:23 -05:00
2 changed files with 83 additions and 18 deletions

View File

@ -122,7 +122,7 @@ const codeHtml = highlightCode(trimAndDedent(code));
<div class="p-1 border-b border-white">state</div>
<div class="h-24 p-1">
<template x-for="(value, key) in state">
<div x-text="key + ' = ' + value"></div>
<div x-text="key.replaceAll(' ', '&nbsp;') + ' = ' + value"></div>
</template>
</div>
</div>
@ -138,7 +138,7 @@ const codeHtml = highlightCode(trimAndDedent(code));
</div>
<script>
type Instruction = "line" | "out" | "set";
type Instruction = "line" | "out" | "set" | "unset";
type AlpineState = {
line: number,
stdout: string,
@ -170,6 +170,10 @@ const codeHtml = highlightCode(trimAndDedent(code));
data.state[String(instructionArr[1])] = String(instructionArr[2]);
break;
}
case "unset": {
delete data.state[String(instructionArr[1])];
break;
}
}
}

View File

@ -86,36 +86,97 @@ Use a naked `try` when you want to rethrow an error, if there is any.
steps={`[
[["line", 14]],
[["line", 7]],
[["line", 10]],
[["line", 1]],
[["line", 3]],
[
["line", 8],
["set", "= = =", "run() = = = ="]
],
[
["line", 10],
["set", "result", 50]
["set", " dangerous()", "..."],
],
[["line", 1]],
[
["line", 2],
["set", " = = =", "dangerous() = = = ="]
],
[["line", 3]],
[
["set", " Math.random()", "0.2"]
],
[
["unset", " Math.random()"],
["set", " return", "Int 50"]
],
[["line", 5]],
[
["line", 10],
["unset", " return"],
["unset", " = = ="],
["set", " dangerous()", "Int 50"]
],
[
["unset", " dangerous()"],
["set", " Int result", "Int 50"]
],
[["line", 11]],
[
["line", 14],
["line", 12],
["out", "The result is 50\\n"],
],
[
["line", 15],
["set", "res1", "<empty>"],
["line", 14],
["unset", " Int result"],
["unset", "= = ="],
],
[
["line", 15],
["set", "!Exception res1", "<empty>"],
],
[["line", 7]],
[["line", 10]],
[["line", 1]],
[["line", 3]],
[["line", 4]],
[
["line", 8],
["set", "= = =", "run() = = = ="]
],
[
["line", 10],
["set", "result", "Exception(\\"Unlucky\\")"]
["set", " dangerous()", "..."],
],
[["line", 15]],
[["line", 1]],
[
["line", 0,],
["set", "res2", "Exception(\\"Unlucky\\")"],
]
["line", 2],
["set", " = = =", "dangerous() = = = ="],
],
[["line", 3]],
[
["set", " Math.random()", "0.9"],
],
[
["line", "4"],
["unset", " Math.random()"],
["set", " return", "Exception(\\"Unlucky\\")"],
],
[["line", 5]],
[
["line", 10],
["unset", " return"],
["unset", " = = ="],
["set", " dangerous()", "Exception \\"Unlucky\\""],
],
[
["line", 12],
["unset", " dangerous()"],
["set", " return", "Exception(\\"Unlucky\\")"],
],
[
["line", 15],
["unset", " return"],
["unset", "= = ="],
],
[
["line", 16],
["set", "!Exception res2", "Exception(\\"Unlucky\\")"],
],
]`}
></InteractiveCode>