[plt-scheme] verifying whether a symbol is defined at compile time?

From: jos koot (jos.koot at telefonica.net)
Date: Sun Apr 22 05:51:21 EDT 2007

Hi Yinso
Did you read section 5.2.1 of R5RS? (easily accessible via de help menu)
No, namespace-defined? cannot see whether or not the variable will be defined at run time. Compile and run time are separated. See 
first section of chapter 12 of the PLT MzScheme Language manual.
Keeping track of the defined/undefined status of a variable during expansion time is a tricky bussines. Even at run time procedure 
namespace-defined? only looks at top level bindings; it does not see local bindings.
In case procedure namespace-set-variable-value! is used, especially when called within a conditional form, it is even impossible to 
predict during expansion time whether or not a variable will be defined at top level.

For example:

(require (lib "etc.ss"))

(define-syntax my-define
 (syntax-rules ()
  ((my-define (name . args) . body) (my-define name (lambda args . body)))
  ((my-define var value)
   (define name
    (begin
     (printf "my-define ~a status is ~s~n" 'var
      (if (namespace-defined? 'var) 'defined 'undefined))
     value)))))

(if (read) (namespace-set-variable-value! 'b 2))
(my-define b 2)


Jos Koot

(((((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: Yin-So Chen
  To: mzscheme Mailing List
  Sent: Sunday, April 22, 2007 10:57 AM
  Subject: [plt-scheme] verifying whether a symbol is defined at compile time?


  Hi all -

  Is there a way to verify whether a symbol is defined (or imported) at compile time?  I am trying to write a conditional define 
macro (e.g. define-once) that will evaluate to define if the variable is not previously defined, but struggling to figure out how to 
determine whether a symbol's existence.  (namespace-defined? v) doesn't appear to work for compile-time.

  Thanks,
  yinso

  -- 
  http://www.yinsochen.com
  ...continuous learning...


------------------------------------------------------------------------------


  _________________________________________________
    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/20070422/899776bd/attachment.html>

Posted on the users mailing list.