Re: delimited continuations; was: SRFI 225: Dictionaries Ray Dillinger 21 Jul 2021 23:34 UTC

No doubt about it, continuations are deeply weird.  Procedures may
return a different number of times than they are called, in unexpected
sequences, or to the call sites where completely different functions
were called.  That breaks a whole lot of user expectation for those
unfamiliar, and It's a lot to take in. 

I'm of the opinion that continuations are easiest to learn, think about,
and use, if they represent a return from some specific user-defined
function.  I've actually managed to teach some people about
continuations this way who didn't seem to get it with any other
explanation. 

Many languages have a "return(value)" form that a routine can use to
exit and return control to the site where it was called.  So just think
of 'return' as a function with the rule that every scope binds a
"return" value every time it's entered.  If you call it the procedure
returns to its call site.  In lisp, functions are values, so you can do
other things with it too   So let's say routine 'bar' passes it to a
subroutine or writes it into a structure so it's available to other
routines.  And whenever some routine calls it in the future (instead of
calling the "return" that was bound with its own scope), it will return
control to bar's caller.

This idea of "return" as a variable bound as a scope is entered, whose
value can be accessed, seems more accessible to most. 

And once they've got the idea of these relatively simple procedure-based
"returns", I can explain the rest by giving them a short, simple, but
relatively brain-bending definition.

(define call-cc (lambda(arg) (arg return)))

Honestly, I would find scheme with a "return" variable implicitly bound
in each new scope to be more intuitive.  "Return" seems nicer than
call-cc as syntax, and makes the language expressive enough to define
call-cc without resorting to syntax.

            Bear,
            Apropos of nothing.