[plt-scheme] namespace-variable-value

From: jos koot (jos.koot at telefonica.net)
Date: Fri Apr 27 13:30:26 EDT 2007

Module level variables can be assigned to only by the module itself. In this way the writer of a module is assured that the user of 
the module cannot corrupt the variables.
Matthias Felleisen already suggested to use boxes in stead of variables:

(module lang mzscheme
  (provide f)
  (define f (box 'who-cares?)))

(module test mzscheme
  (require lang)
  (set-box! f 1)
  (provide test1)
  (define (test1) (unbox f)))

(require test)
(test1) ; --> 1

Jos

(((((lambda(x)((((((((x x)x)x)x)x)x)x)x))
    (lambda(x)(lambda(y)(x(x y)))))
   (lambda(x)(x)x))
  (lambda()(printf "Greetings, Jos~n"))))
  ----- Original Message ----- 
  From: support at taxupdate.com
  To: jos koot
  Cc: plt-scheme at list.cs.brown.edu
  Sent: Friday, April 27, 2007 2:09 PM
  Subject: Re: [plt-scheme] namespace-variable-value



  On Fri, Apr 27, 2007 at 06:41:34PM +0200, jos koot wrote:

  > (module lang mzscheme
  >   (printf "defining~n")
  >   (namespace-set-variable-value! 'f 1))
  >
  > (module test mzscheme
  >   (require lang) ; does the top level assignment (once only)
  >   (provide (all-defined))
  >   (define (test1) (namespace-variable-value 'f))) ; refers to the top level
  >
  > (require test) ;; prints defining
  > (test1)        ;; --> 1
  > (require lang) ;; does nothing

  I'm hoping to set module-level variables, not top-level.  My understanding
  of the docs leads me to believe that namespace-variable-value can use
  mapping to return imported variable mappings.

  Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20070427/80ff9f84/attachment.html>

Posted on the users mailing list.