[plt-scheme] Graphics Questions

From: Doug Williams (m.douglas.williams at gmail.com)
Date: Sun Nov 25 19:52:54 EST 2007

I'm trying to implement a generic graphics framework to use for my
simulations and want to include Run and Stop buttons.  I've abstracted it to
the attached example to ask my questions.  The code doesn't do anything
interesting - just some looping to take the place of real code, but it does
have the basic graphical elements I want.  This code works fine for simple
Run and Stop.  But, I would like to be able to restart the computation after
a Stop (i.e., make it a Pause).  I added the *continue* global variable to
store a continuation inside the internal loop.

Unfortunately, when I modify the Run button code as follows

(define run-button (instantiate button%
                     ("Run" panel-1)
                     (horiz-margin 4)
                     (callback (lambda (b e)
                                 (if *break*
                                       (set! *break* #f)

I get an error "continuation application: attempt to cross a continuation
barrier".  I assume MrEd is using threads or other elements that cause the
continuation barrier.

For the example, I'd like the Run button to continue after a Stop or
(re)start otherwise (i.e., the first time or if the computation has
completed).  Does anyone have a suggestions?

The example code is below and is also included in the attached file.

(define n 10000)
(define *break* #f)
(define *continue* #f)

(define (test-run)
      ((current-output-port (open-output-text-editor text)))
    (set! *break* #f)
    (send run-button enable #f)
    (send gauge set-range n)
    (send gauge set-value 0)
    (let/cc exit
      (do ((i 1 (+ i 1)))
        ((> i n) (void))
        (let/cc next
          (set! *continue* next)
          (if *break* (exit))
          (do ((j 0 (+ j 1)))
            ((= j 1000) (void))
          (send text erase)
          (printf "~a~n" i)
          (send gauge set-value i))))
    (printf "I counted to ~a.~n" (send gauge get-value))
    (send run-button enable #t)

;;; Graphics

(define frame (instantiate frame% ("Test Control Strategy")))

(define menu-bar (instantiate menu-bar% (frame)))

(define file-menu (instantiate menu% ("&File" menu-bar)))

(define exit-menu-item (instantiate menu-item% ("E&xit" file-menu)
                         (callback (lambda (mi e)

(define edit-menu (instantiate menu% ("&Edit" menu-bar)))

(define panel-1 (instantiate horizontal-panel% (frame)
                  (alignment '(right center))))

(define run-button (instantiate button%
                     ("Run" panel-1)
                     (horiz-margin 4)
                     (callback (lambda (b e)

(define stop-button (instantiate button%
                      ("Stop" panel-1)
                      (horiz-margin 4)
                      (callback (lambda (b e)
                                  (set! *break* #t)))))

(define canvas (instantiate editor-canvas% (frame)
                 (min-width 500)
                 (min-height 450)
                 (style '(no-hscroll hide-vscroll))))

(define text (instantiate text% ()))

(send canvas set-editor text)

(define gauge (instantiate gauge% ("Progress" 1 frame)))

(send frame show #t)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20071125/c4282487/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test-control.ss
Type: application/octet-stream
Size: 2097 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20071125/c4282487/attachment.obj>

Posted on the users mailing list.