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

From: Yin-So Chen (yinso.chen at gmail.com)
Date: Sun Apr 22 06:32:36 EDT 2007

Hi Jos -

Thanks for the quick response and the helpful answer (the references/example
are great).  My motivation for having a conditional define is to make it
play nice with the module system, which doesn't work well when having
multiple definitions with the same name.  I was hoping there is an
"automated" way of detecting whether a symbol is already defined in the
current module, if so, either override or not import the definition.

Of course this is probably circumventing module's design (seems that module
is *a lot* stricter than REPL by design), but I am certainly curious on how
this could be done.  Seems like that compiler would have to keep symbol
table(s) internally for all of the defined symbols in order to throw the
"already defined" error... ;)

Thanks,
yinso


On 4/22/07, jos koot <jos.koot at telefonica.net> wrote:
>
>  Oops, the contra-example should read:
>
> (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 var ; <== correction
>     (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
>



-- 
http://www.yinsochen.com
...continuous learning...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20070422/75ca3808/attachment.html>

Posted on the users mailing list.