3 ms·
While I don't have a definitive formulation in mind, this seems like exactly the sort of problem that can be solved with delimited continuations by 'augmenting'
by discardable_dan 9y ago
While I don't have a definitive formulation in mind, this seems like exactly the sort of problem that can be solved with delimited continuations by 'augmenting' any outer continuation with a code to perform the file-pointer closing.
That said, I'm not certain demanding these operations use `unwind-protect` is desirable. Several dialects of Scheme use continuations for multithreading, and forcing the program to close a file handle before context-switching also seems like incorrect behavior: if I ever end up back in the file-reading context, it sure would be nice if that file was still open. The author proposes that we should indicate if we intend to do this in each continuation case (either at `call/cc` or continuation invocation time), which seems annoying and cumbersome.
The alternative, then, which the author seems to ignore, is to trust the garbage collector to do the correct thing. Luckily, any BiBoP mark-and-sweep collector for Scheme [0] will almost certainly handle this situation when the file handle is out of scope (by correctly closing handles during the compacting step).
0. http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.51.4490 http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.51.4...