Lecture 16 Summary, CSE 341 Spring 2004 Continuations * A "continuation" represents the rest of computation. * Some languages (Scheme, SML, Stackless Python, ...) provide "first-class continuations", giving you a binding for "forget your current computation and instead complete this computation with an argument 'filling the hole' " * The key idiom for this is "escaping out of computations" for efficiency or exception handling. * Exception handlers can do these idioms too * A related idiom does not need language support like Scheme's call/cc: By passing a function for "what to do for the rest", we can do important things elegantly like iterate over trees. You're not responsible for the following, but it's very cool: * What makes let/cc more powerful than exceptions is: * it's first-class (unlike exception handlers, you can make a list of continuations, etc.) (you can code up non-preemptive scheduling) * you can "time travel" -- re-enter a scope that was already exited -- there's an example in the code for class that iterates over trees this way