resume-to transfers control to the nearest enclosing resumable branch that matches the supplied resumption value.
Syntax
(resume-to ⟨resumption-expr⟩)
Semantics
⟨resumption-expr⟩must have a type:rthat is an instance of theResumptiontype class (which holds exclusively for types defined withdefine-resumption).resume-tohas the polymorphic behaviorResumption :r => :r -> :aand unifies with any expected return type because it never returns locally.- Evaluating
(resume-to ⟨resumption-expr⟩)searches dynamically enclosingresumableforms from innermost to outermost for a branch matching the resumption value, unwinds the stack to thatresumableform (running any interveningprotectcleanup forms), and evaluates the matching branch body. - If no active
resumablebranch matches the resumption value, a runtime error is signaled. resume-tois most commonly called inside ahandlebranch, which executes before unwinding the stack and can therefore reach resumptions established inside thehandle’s guarded expression. Callingresume-toinside acatchbranch can only reachresumablehandlers outside thecatch.
Examples
(coalton-toplevel
(define-resumption (UseDefault Integer))
;; Polymorphic helper that invokes any resumption
(declare invoke (Resumption :r => :r -> :a))
(define (invoke r)
(resume-to r))
(declare compute-with-fallback (Boolean -> Integer))
(define (compute-with-fallback use-default?)
(resumable
(progn
(when use-default?
(resume-to (UseDefault 42)))
100)
((UseDefault n) n))))
Other notes
- When the concrete resumption type is statically known at the
resume-tosite, Coalton compiles(resume-to expr)directly to(cl:invoke-restart 'ResumptionName ...); when the resumption type is a type variable constrained byResumption :r, it dispatches throughcoalton-impl/runtime:invoke-resumption. - See
define-resumption,resumable, andhandle.