[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Using continuations in user-interfaces



Hello,

I have been experimenting with the use of continuations to structure event
driven UI applications, and I have hit a snag.

Here is my program:

;;; start

(define no-fn (lambda (x y) ()))

(define (show-window1 cont)
  (let* ((w (make-object frame% "Enter Name" #f 200 200))
         (e (make-object text-field% "Name" w no-fn))
         (b (make-object button% "Next" w
              (lambda (button event)
                (send w show #f)
                (cont (send e get-value))))))
    (send w show #t)))

(define (show-window2 cont)
  (let* ((w (make-object frame% "Enter Address" #f 200 200))
         (e (make-object text-field% "Address" w no-fn))
         (b (make-object button% "Next" w
              (lambda (button event)
                (send w show #f)
                (cont (send e get-value))))))
    (send w show #t)))

(define (wizard)
  (display (call/cc show-window1))
  (display (call/cc show-window2)))

(wizard)

;;; end

What I assumed would happen is that the first window would be shown, then,
when the "next" button is pressed, it would be replaced by the second
window, and then clicking on the next button would close that window and end
the computation.  The name and address values would be displayed after
pressing the next buttons.

What actually happens (in DrScheme) is that *both* windows are shown
simultaneously, two <void> values are displayed in the interactions window,
and pressing either of the next buttons produces the following error
message:

continuation application: attempted to cross a continuation boundary

Is this call/cc thing impossible in DrScheme, or is it just that I'm barking
up the wrong tree with this continuation technique?

TIA,

- jde