[plt-scheme] GUIBuilder HOWTO

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Thu Sep 2 11:39:07 EDT 2004

At Thu, 2 Sep 2004 10:18:28 -0500, Corey Sweeney wrote:
> And how do you block a continuation?  Is this a R5RS thing, or a
> drscheme "special" thing?

The idea is built into MzScheme, but here's a blocking function that
will work in most Schemes:

 (define (call-with-jumps-blocked f)
   (let ([result #f]
         [entered? #f])
     (let/cc stop
       (dynamic-wind
         (lambda () (if entered? (car 0)) ; error to prevent re-entry
                    (set! entered? #t))
         (lambda () (set! result (f)))
         (lambda () (stop result))))))


 > (call-with-jumps-blocked (lambda () 10)) 
 10
 > (let/cc k (call-with-jumps-blocked (lambda () (k 10))))
 #f ; blocked
 > (define k (call-with-jumps-blocked (lambda () (let/cc k k))))
 > (k 10)
 car: expects argument of type <pair>; given 0

The `call-with-jumps-blocked' function relies on calling a continuation
in a dynamic-wind post thunk, which is not defined in R5RS. (Also,
`(car 0)' is a clumsy attempt to signal an error, which is undefined in
R5RS on several levels.)


Matthew



Posted on the users mailing list.