[plt-scheme] fluid-let (version 103p1)
#|QUESTION/REMARK
Consider: a fluid-let form in DrScheme, version 103p1
-that dynamically assigns a value "original" to a variable
-whose body assigns a new value "new" to this variable
-then exits the dynamic extent of the fluid-let form by means
of a continuation
-then regains control because a continuation is called that is
located in the dynamic extent of the fluid-let form
It appears that fluid-let restores the "original" value,
not the "new" value. See example 1. For me it seems more logical
fluid-let to behave like example 2. |#
;Welcome to DrScheme, version 103p1.
;Language: Graphical Full Scheme (MrEd).
;Example 1
(define a 10)
(define b 20)
(define (printer) (write (list a b)) (newline))
(define done? #f)
(let
((return
(let/cc call
(fluid-let ((a 100) (b 200))
(printer)
(set! a 1000) (set! b 2000)
(let/cc return (call return))
(printer)))))
(if (not done?)
(begin (set! done? #t) (printer)
(set! a 10000) (set! b 20000) (return (void))))
(printer)
(void))
;written:
;(100 200)
;(10 20)
;(100 200)
;(10 20)
;Welcome to DrScheme, version 103p1.
;Language: Graphical Full Scheme (MrEd).
;Example 2
(define a 10)
(define b 20)
(define (printer) (write (list a b)) (newline))
(define done? #f)
(let
((return
(let/cc call
(let ((values '(100 200)))
(let
((switch-values
(lambda ()
(define temp (list a b))
(set! a (car values))
(set! b (cadr values))
(set! values temp))))
(dynamic-wind
switch-values
(lambda ()
(printer)
(set! a 1000) (set! b 2000)
(let/cc return (call return))
(printer))
switch-values))))))
(if (not done?)
(begin (set! done? #t) (printer)
(set! a 10000) (set! b 20000) (return (void))))
(printer)
(void))
;written:
;(100 200)
;(10 20)
;(1000 2000)
;(10000 20000)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20041126/f2fa9c73/attachment.html>