[plt-scheme] Re: call/cc vs let/cc at top level - A BUG?

From: Kyle Smith (airfoil at bellsouth.net)
Date: Mon Jan 1 13:04:08 EST 2007

In the code below you'll find a much leaner set of examples which demonstrate 
the different manner in which call/cc and let/cc handle a simple scenario, 
this time based on a regular variable.  I've taken the parameter out of the 
equation, and the difference in behaviour persists.  This version of examples 
does not include any of my helper syntax, nor does it try to make the point 
about how the primitive functions for prompts produce consistent behaviour 
across the board.  That case was made in my last post regarding this issue.  
This follow up is simply to provide a cleaner demonstration and to make the 
point that it does not seem to have anything to do with parameterization.

Hope you all had a Happy New Year.

--kyle
airfoil at bellsouth dot net
schemekeys.blogspot.com

-----------BEGIN CODE EXAMPLES---------------------


(define p 1)
(define cc 'takes-a-continuation)
(begin
  (call/cc (lambda (k) (set! cc k)))
  (display 'a= )(display p)(newline))
(display "ONE")(newline)
(cc 10)
(display "TWO")(newline)
(set! p 2)
(display "THREE")(newline)
(cc 10)
(display "~~~~~~~~~~~~~~~~~~~~~~")
(newline)
#|
=>
a=1
ONE
a=1
TWO
THREE
a=2
~~~~~~~~~~~~~~~~~~~~~~
|#
(collect-garbage)
(define (a)
  (define p 1)
  (define cc 'takes-a-continuation)
  (begin
    (call/cc (lambda (k) (set! cc k)))
    (display 'a=)(display p)(newline))
  (display "ONE")(newline)
  (cc 10)
  (display "TWO")(newline)
  (set! p 2)
  (display "THREE")(newline)
  (cc 10)
  (display "~~~~~~~~~~~~~~~~~~~~~~")
  (newline)
)
(define a-td (thread a))
(sleep 0.001)
(kill-thread a-td)
(sleep 0.1)
(newline)
#|
=>
a= 1 
111111111111111111111111111 
a= 1 
111111111111111111111111111
   ...
  forever
|#
(collect-garbage)
(define (b)
  (define p 1)
  (define cc 'takes-a-continuation)
  (begin
    (let/cc k (set! cc k)
    (display 'b=)(display p)(newline)))
  (display "ONE")(newline)
  (cc 10)
  (display "ONE")(newline)
  (set! p 2)
  (display "ONE")(newline)
  (cc 10)
  (display "~~~~~~~~~~~~~~~~~~~~~~")
  (newline)
  )
(define b-td (thread b))
(sleep 0.001)
(kill-thread b-td)
(sleep 0.1)
(newline)
#|
b= 1
ONE
ONE
  ...
 forever
|#

(define p 1)
(define cc 'takes-a-continuation)
(begin
  (let/cc k (set! cc k)
    (display 'b=)(display p)(newline)))
(display "ONE")(newline)
(cc 10)
(display "TWO")(newline)
(set! p 2)
(display "THREE")(newline)
(cc 10)
(display "~~~~~~~~~~~~~~~~~~~~~~")
(newline)
#|
=>
b=1
ONE
10
TWO
THREE
10
~~~~~~~~~~~~~~~~~~~~~~
|#



Posted on the users mailing list.