call-cc-example-break-to-repl


Michael-Micek

The code does what I expect, but the comments may not be helpful and there's probably a better way to illustrate this.


 ;;; This is a framework for breaking out from the middle of a 
 ;;; program to get an arbitrary value 
  
 (define repl #f)    ; This will hold the continuation that breaks out of the program 
 (define return #f)  ; This will hold the continuation to go back in 
  
 ;; PLAY is the main program 
 (define (play)  
   (call-with-current-continuation 
     (lambda (main-continuation) 
       (set! repl main-continuation) 
       (guess)))) 
  
 ;; GUESS needs to generate a value for the program 
 (define (guess) 
   (let ((c (call-with-current-continuation get-value))) 
     (display (car c)) 
     (display " and ") 
     (display (cdr c)) 
     (newline))) 
  
 (define (get-value cont) 
   (set! return cont) 
   (repl "call (return '(c . b)) to continue")) 

category-learning-scheme