[plt-scheme] mutating module variables

From: Daniel Silva (dansilva at lynx.dac.neu.edu)
Date: Tue Apr 29 18:34:33 EDT 2003


Is this good behavior?  Seems like the set! in redefine_x.scm should not
affect the loaded define_x module in use_redefined_x.scm.  Would it be
better for set! to not change things everywhere, and leave that to the
function you get back from make-parameter?

In most operating systems you can load libraries with copy-on-write so
you don't get a horrible performance penalty of loading list.ss 500000
times when starting DrScheme, but you do get a fresh copy in case you
want to change it.  Would it be a bad thing for MzScheme to have that
sort of copy-on-write for its dynamically-linked libraries (modules) as

[~/plt/collects/python/tests/scm] > cat define_x.scm
(module define_x mzscheme
  (provide (all-defined))

  (define x 2)
  (define (set-x! v) (set! x v)))

[~/plt/collects/python/tests/scm] > cat redefine_x.scm
(module redefine_x mzscheme
  (provide (all-defined))

  (require (prefix define_x. "define_x.scm"))

  (define_x.set-x! 7))

[~/plt/collects/python/tests/scm] > cat use_redefined_x.scm
(require (prefix define_x. "define_x.scm"))
(printf "at first x is two: ~a~n" define_x.x)
(define_x.set-x! 1)
(printf "you should see the number one: ~a~n" define_x.x)
(require (prefix redefine_x. "redefine_x.scm"))
(printf "now x is mutated by an outsider to seven: ~a~n" define_x.x)

[~/plt/collects/python/tests/scm] > mzscheme -r use_redefined_x.scm
at first x is two: 2
you should see the number one: 1
now x is mutated by an outsider to seven: 7

- Daniel

Posted on the users mailing list.