<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.6000.16414" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV>Hi Wayne,</DIV>
<DIV>I have been away for some days. Therefore I could not respond earlier. I
hope others have cleared up things in the meantime. You can try
"identifier-binding" as follows:</DIV>
<DIV> </DIV>
<DIV>(module a mzscheme<BR> (define-struct not-defined ())<BR> (define
undefined? not-defined?)<BR> (define undefined
(make-not-defined))<BR> (define-syntax (value/binding stx)<BR>
(syntax-case stx ()<BR> ((value/binding
symbol)<BR> (let ((binding-type (identifier-binding
#'symbol)))<BR> #`(values<BR>
#,(cond<BR> ((eq? binding-type 'lexical)
#'symbol)<BR> ((not binding-type)
#'(namespace-variable-value 'symbol #t (lambda ()
undefined)))<BR> (else
#'symbol))<BR> '#,binding-type)))))<BR> (provide
value/binding undefined?))</DIV>
<DIV> </DIV>
<DIV>(module b mzscheme<BR> (define b 1)<BR> (provide b))</DIV>
<DIV> </DIV>
<DIV>(require a b)<BR>(define c 2)<BR>(value/binding b) ; --> 1 (b b b b
#f)<BR>(value/binding c) ; --> 2 #f<BR>(value/binding d) ; -->
#<struct:not-defined> #f<BR>(define d 3)<BR>(value/binding d) ; --> 3
#f<BR>(let ((e 4)) (value/binding e)) ; --> 4 lexical</DIV>
<DIV> </DIV>
<DIV>(module x mzscheme<BR> (require a b)<BR> (define c
20)<BR> (define-syntax print-value/binding<BR> (syntax-rules
()<BR> ((print-value/binding x)<BR> (apply printf
"~s ~s~n" (call-with-values (lambda () (value/binding x))
list)))))<BR> (print-value/binding b) ; prints 1 (b b b b
#f)<BR> (print-value/binding c) ; 20 (#<module-path-index> c
#<module-path-index> c #f)<BR> ; (print-value/binding d) ; error:
reference to an identifier before its definition: d<BR> (define d
30)<BR> (print-value/binding d) ; 30 (#<module-path-index> d
#<module-path-index> d #f)<BR> (let ((e 40)) (print-value/binding
e))); prints 40 lexical</DIV>
<DIV> </DIV>
<DIV>(require x)</DIV>
<DIV> </DIV>
<DIV>Notice that the binding-type is determined at expansion/compilation time.
Things may go wrong when a (current-namespace other-namespace) is
done during execution time. Also notice that there are some subtle differences
between modules and the top level. E.g, a module defined variable (d in the
example) is seen in the module as being defined even above its
definition, but it is not allowed to refer to this variable above its
definition.</DIV>
<DIV>Jos</DIV>
<DIV> </DIV>
<DIV>(((((lambda(x)((((((((x x)x)x)x)x)x)x)x))<BR>
(lambda(x)(lambda(y)(x(x y)))))<BR> (lambda(x)(x)x))<BR>
(lambda()(printf "Greetings, Jos~n"))))</DIV>
<BLOCKQUOTE
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV
style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B>
<A title=support@taxupdate.com
href="mailto:support@taxupdate.com">support@taxupdate.com</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=jos.koot@telefonica.net
href="mailto:jos.koot@telefonica.net">jos koot</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Cc:</B> <A title=plt-scheme@list.cd.brown.edu
href="mailto:plt-scheme@list.cd.brown.edu">plt-scheme@list.cd.brown.edu</A>
</DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Monday, April 30, 2007 1:00
PM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> Re: [plt-scheme]
namespace-variable-value</DIV>
<DIV><BR></DIV>Jos,<BR><BR>On Fri, Apr 27, 2007 at 09:55:15PM +0200, jos koot
wrote:<BR>> Why doesn't namespace-variable-value pick up the
mapping in the current-namespace?<BR><BR>> It does, but the current
namespace is not used for the body of a module. Each module has its own
special 'namespace' such as to <BR>> protect its variables and to make
syntaxes hygienic by not confusing module variables and syntaxes with those of
the importing <BR>> module (or the top level) MHO.<BR><BR>Is there a way to
determine if a given symbol has been defined/imported into a
module's<BR>namespace (given only the symbol)? For
example:<BR><BR>(module x mzscheme<BR> (require
...)<BR> <BR> ;;
test whether sym is defined or mapped to a value:<BR>
(define (defined/imported sym)<BR>...) <BR>)<BR><BR>It seems that
namespace-variable-value almost does this, but for imported<BR>mappings, it
would need the imported module name.<BR><BR>Wayne<BR></BLOCKQUOTE></BODY></HTML>