Closed jpolitz closed 6 years ago
We can simulate throwing with something like this:
function throwableControl(f) {
const r = control(
k => ({ type: 'normal', value: f(r => k({ type: 'normal', value: r})),
r => k({ type: 'exception', value: r}))});
const r = control(k => f(k));
if (r.type === 'exception') {
throw r.value;
}
else {
return r.value;
}
}
throwableControl((returnK, throwK) => ... );
I'm not sure what it means to do continue
and break
.
This is addressed by 33b9f6212240d45dfe8cddd44df9619604980786.
When Pyret pauses the stack, you can restart it in more than one way.
The important one is that the client of
pauseStack
can choose to callresume
orerror
callbacks; the latter simulates athrow
on the original stack.With Stopify, it's "easy" to simulate it is by looking for a special return value (e.g. turn all resumes into
Either
-returning evaluations). This requires rewriting more code in Pyret than is particularly nice to do, and is a fundamentally different interface.In the limit for Stopify this could mean supporting
throw
,continue
,break
, etc as restart options.I suspect in practice
throw
is the only one that matters, but it does matter.