I spent a few days of mulling to come up with the simple code below. exit is a procedure of one argument, that can be provided to Scheme code. When exit is invoked it discards its argument are returns to the command prompt for a new Scheme expression to evaluate. Exercise: explain the purpose of the recursive reference to exit in its own definition.
The routine mer takes a string, or any other sort of label, and returns an escape procedure which prints the label and the argument passed, and then reports back for more input via the Read-Evaluate-Print loop.
(define exit (let* ((s (cons 0 0)) (z (call-with-current-continuation (lambda (e) (cons s e))))) (if (and (pair? z) (eq? (car z) s)) (cdr z) exit))) (define mer (lambda (x) (let ((r (call-with-current-continuation (lambda(d) (cons #f (lambda(y) (d (cons #t y)))))))) (if (car r) (begin (write (list "Exception:" x (cdr r))) (newline) (exit 0)) (cdr r)))))