(define stored-continuations null) (define exit null) (define set-exit! (lambda () (let/cc k (set! exit k)))) (define remember (lambda (cont) (let ((cid (string->symbol (string-append "c" (number->string (random 1000)))))) (set! stored-continuations (cons (cons cid cont) stored-continuations)) cid))) (define recall (lambda (cid) (cdr (assoc cid stored-continuations)))) (define resume (lambda (cid val) ((recall cid) val))) (define local-prompt (lambda (prompt) (display prompt) (read))) (define local-result (lambda (result) (display result) (newline))) (define web-prompt (lambda (prompt) (let/cc k ; Generate a name for the continuation that we ; can use later. (let ((cont (remember k))) ; Code to build a Web page simulated (display "[") (display cont) (display "] ") (display prompt) (newline)) ; That's it (exit)))) (define web-result (lambda (result) (display "") (display result) (display "</title</head>") (newline) (display "<body><p>") (display result) (display "</p></body></html>") (newline))) (define prompt local-prompt) (define result local-result) (define local (lambda () (set! prompt local-prompt) (set! result local-result))) (define web (lambda () (set! prompt web-prompt) (set! result web-result))) (define silly (lambda () (let ((op (prompt "Please enter the desired operation "))) (cond ((eq? op 'square) (let ((val (prompt "Please enter a number "))) (result (* val val)))) ((eq? op 'add) (let* ((left (prompt "Please enter a number ")) (right (prompt "Please enter another number "))) (result (+ left right)))) (else (result "Invalid operation.") (silly)) ) ) ) ) (set-exit!)