David Kastrup <d...@gnu.org> writes: > Noah Lavine <noah.b.lav...@gmail.com> writes: > >> Hello, >> >>> Sure, but things like gensym and make-prompt-tag (and (list '()) for >>> creating an eq?-unique object) are artificial hygiene coming at a cost >>> in symbol table and symbol generation time rather than "lexical" >>> hygiene. They need _extra_ work, whereas the >>> call-with-current-continuation approach needed _less_ work. Basically I >>> want something like call-with-single-continuation that will only allow >>> one return (and any dynwind out counts and should work if it is the >>> first, so it is not exactly equivalent to using >>> with-continuation-barrier) and come without the stack-copying cost of >>> call-with-current-continuation. >> >> I agree that it's not pretty. We have hygienic macros so we don't have >> to use gensym, after all. But I don't know of a better way. > > Well, to wrap this up: the manual (not current) states > > It is traditional in Scheme to implement exception systems using > `call-with-current-continuation'. Continuations (*note > Continuations::) are such a powerful concept that any other control > mechanism -- including `catch' and `throw' -- can be implemented in > terms of them. > > [...] > > The more targeted mechanism provided by `catch' and `throw' does not > need to save and restore the C stack because the `throw' always jumps > to a location higher up the stack of the code that executes the > `throw'. Therefore Guile implements the `catch' and `throw' primitives > independently of `call-with-current-continuation', in a way that takes > advantage of this _upwards only_ nature of exceptions. > > > I think that using something like "call-with-single-continuation" as the > underlying primitive would make Guile quite more similar to > "traditional" systems in the code base. It would also provide a > minimally-invasive tool for tuning existing code based on > call-with-current-continuation in case that the stack copying semantics > are _not_ required. Definitely more Schemeish than stuff like, uh, > prompts? > Just to throw my two cents in: Racket (and probably other Schemes) provide this primitive under the name call-with-escape-continuation (call/ec):
http://docs.racket-lang.org/reference/cont.html?q=call/ec#%28def._%28%28quote._~23~25kernel%29._call-with-escape-continuation%29%29 Regards, Rotty -- Andreas Rottmann -- <http://rotty.yi.org/>