[r6rs-discuss] [Formal] eliminate library export immutability loophole

AndrevanTonder andre at het.brown.edu
Mon Mar 12 18:05:10 EDT 2007


On Sun, 11 Mar 2007, R. Kent Dybvig wrote:

> Okay, here's one example:
>
>  (library (L1)
>    (export y get-y set-y!)
>    (import (r6rs))
>    (define x (call/cc (lambda (k) (list 0 k values))))
>    (define y (car x))
>    (define z ((caddr x)))
>    (define get-y (lambda () y))
>    (define set-y!
>      (lambda (v)
>        (call/cc (lambda (k) ((cadr x) (list v (cadr x) k)))))))

I think there is an error.  Here is a working version:

    (library (L1)
      (export y get-y set-y!)
      (import (r6rs))
      (define x (call/cc (lambda (k) (list 0 k values))))
      (define y (car x))
      (define z ((caddr x) #f))     ; modified line
      (define get-y (lambda () y))
      (define set-y!
        (lambda (v)
          (call/cc (lambda (k) ((cadr x) (list v (cadr x) k)))))))

> By my reading of the current library description, the program:
>
>  (import (r6rs) (L1))
>  (write (list y (get-y))) (newline)
>  (set-y! 3)
>  (write (list y (get-y))) (newline)
>
> prints
>
>  (0 0)
>  (0 3)

I get the following, which I think is also consistent with the current 
specification:

   (0 0)
   (3 3)

This happens if exported variables are translated to shared r5rs toplevel 
globals, which is a possible implementation of the shared semantics.

Andre





More information about the r6rs-discuss mailing list