Trying to understand delimited continuations with Guile scheme
I managed to grasp the vanilla conts (call/cc) thanks to this video (it's great)
Now I'd like to move to delimited conts
I have this minimal example of early exit made with call/cc
(define (my-early-exit)
(let ((
my-val (call/cc
(lambda (the-continuation)
(display "this will be executed")
(display "\n")
(the-continuation 5) ;;early exit
(display "this will not be executed")))))
(display my-val)))
Ok, I can run this, I understand what it does
How can I write a piece of code equivalent to this one using shift and reset ?
I am confused about
shiftandresetbut this is how I understand it, based on some notes I made on a little while ago. I'd welcome clarification and/or correction people who understand this better than I do.The equivalent thing, more or less, would be
So, here (if I understand this!):
resetestablishes a 'place you can get to' in a similar way thatcall/ccdoes, except that there is no explicit variable for it;(shift k ...)will:reset;...withkbound to a continuation (? name) which, if called, will return its argument values from theshiftform and then continue after it.So in this case I am not using
kat all, so the forms after theshiftnever happen. But in this case:Then
And lest this all seem too obvious:
then
There is a good amount of information on
shiftandresethere, although I do not completely understand them.