[plt-scheme] namespace-variable-value

From: jos koot (jos.koot at telefonica.net)
Date: Fri Apr 27 12:41:34 EDT 2007

Hi Wayne,
I regret my earlier posting on using namespace-set-variable-value! for setting variables whose names are determined at run time. 
Your code does not work because modules are separated from top level namespaces. That's (among other things) what makes modules 
safe. The following works, but are you sure you want this? Better suggestions for runtime bookkeeping of symbol/value associations 
have already been posted. IMHO it (usually) is better to forget the top level alltogether and to think in terms of modules only. I 
know from bad experiences that the toplevel is tricky.
Jos Koot

(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

(((((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: plt-scheme at list.cs.brown.edu
  Sent: Friday, April 27, 2007 12:21 PM
  Subject: [plt-scheme] namespace-variable-value


  Based on my understanding of the section "8.3 Namespace Utilities" from the
  docs, I was expecting the following to print a "1":

  (module lang mzscheme
    (provide (all-defined)
             (all-from mzscheme))
    (define f 1))

  (module test lang
    (provide (all-defined))
    (define (test1)
      (display (namespace-variable-value 'f))))

  (require test)
  (test1)     ;; "namespace-variable-value: f is not defined"

  Why doesn't the call to namespace-variable-value in module test succeed?

  Wayne
  _________________________________________________
    For list-related administrative tasks:
    http://list.cs.brown.edu/mailman/listinfo/plt-scheme
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20070427/34a8a9b5/attachment.html>

Posted on the users mailing list.