We provide a function try so that the pattern: (try (lambda (p) x) (lambda (e) y)) performs the code x and if x should call p, then perform code y without return from p. The parameter e, for y, is bound to the value passed to p by x. try returns whatever x or y returns. The continuation created by any call to p is discarded; p does not return.
(define (try pb pe) (call/cc (lambda (p) (pb (lambda (ev) (p (pe ev))))))) (define exc (lambda (t) (write (list "exception" t)) 'e)) (define work (lambda (e) (write "working") 'w)) (define worke (lambda (e) (write "attempting") (e "peculiar") (write "don't get here!"))) (try work exc) ; => "working"w (try worke exc) ; => "attempting"("exception" "peculiar")e