This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: reexport-from-module


Jost Boekemeier writes:

 > > I can see that it's simple, but why do you consider it wrong?  
 > 
 > A symbol can be characterized by its position in the obarray.
 > For example:
 > 
 > guile> (module 'my-module)
 > my-module> (define a 12)
 > my-module> (vector-ref (current-module) 0)
 >
 > #(() () () () () () () () () () () () () () () () () () () () () () ()
 > () () () () () () () () () () () () () () () () () () () () () () ()
 > () () () () () () () () () () () () () () () () () () () () () () ()
 > () () () () () () () () () () () () () () () () () () () () () () ()
 > () () () () () ((a . 12)) () () () () () () () () () () () () () () ()
 > () () () () () () () () () () () () () () () () () () () () () () ()
 > ()) 
 >
 > my-module> a
 > 
 > (gdb) dp sym
 > 0x80f3cb8 "a"
 > (gdb) xsymbol_hash sym
 > 97
 > ^^ occupies position 97 in the current module obarray   
 > 
 > Let's now export symbols `a' and `b'. You will see that---depending on
 > the context---a symbol may have a different meaning.  But a symbol with
 > the name "a" can always be found at position 97.
 > 
 > 
 > my-module> (define (b) (display a))
 > my-module> (vector-ref (current-module) 0)
 > 
 > #(() () () () () () () () () () () () () () () () () () () () () () ()
 > () () () () () () () () () () () () () () () () () () () () () () ()
 > () () () () () () () () () () () () () () () () () () () () () () ()
 > () () () () () () () () () () () () () () () () () () () () () () ()
 > () () () () () ((a . 12)) ((b . #<procedure b ()>)) () () () () () ()
 > () () () () () () () () () () () () () () () () () () () () () () ()
 > () () () () () () () () ())
 > 
 > Note that module `my-module' is a vector that holds an obarray, useslist, 
 > reflist, friendslist, publiclist and a foreign obarray.
 > 
 > my-module> (vector-ref (current-module) 4) 
 > (a b)
 > ^^^^^ publiclist
 > 
 > Also note that `my-module' is a symbol but this symbol is *not* interned
 > in the current module's obarray.
 > 
 > Let's now create a new module that imports all symbols from `my-module':
 > 
 > my-module> (module 'your-module)
 > your-module> (module-open '(my-module))
 > your-module> (vector-ref (current-module) 0)
 > 
 > #(() () () () () () () () () () () () () () () () () () () () () () ()
 > () () () () () () () () () () () () () () () () () () () () () () ()
 > () () () () () () () () () () () () () () () () () () () () () () ()
 > () () () () () () () () () () () () () () () () () () () () () () ()
 > () () () () () () () () () () () () () () () () () () () () () () ()
 > () () () () () () () () () () () () () () () () () () () () () ())
 > 
 > Note that the current obarray is empty!
 > The symbol `a' can be found in the module's foreign_obarray:
 > 
 > (vector-ref (current-module) 5)
 > 
 > #(() () () () () () () () () () () () () () () () () () () () () () ()
 > () () () () () () () () () () () () () () () () () () () () () () ()
 > () () () () () () () () () () () () () () () () () () () () () () ()
 > () () () () () () () () () () () () () () () () () () () () () () ()
 > () () () () () ((a . <my-module (truncated)>)) () () () () () () () ()
 > () () () () () () () () () () () () () () () () () () () () () () ()
 > () () () () () () () ())
 > 
 > In the current foreign_obarray the symbol `a' can still be found at position 
 > 97.  But in this "world" (obarray) the symbol `a' has a different meaning 
 > (value). 
 > 
 > 
 > [...]
 >     vcell = scm_sym2vcell0 (sym, obarray, scm_hash); /* (a . my-module)    */
 >     mod = SCM_CDR (vcell);                           /* my-module          */
 >     obarray = SCM_MODULE_OBARRAY (mod);              /* (vector-ref mod 0) */
 >     vcell = scm_sym2vcell0 (sym, obarray, scm_hash); /* (a . 12)           */
 > [...]

Hmm, I am unable to reproduce the above example using a recent version
of Guile.  What version are you using?  Also, I notice that the obarrays
depicted show "(a . 12)", but for me, the entry displys as:

	(a . #<variable 4017d4e0 name: a binding: 12>)

That is, variables are shown as first-class, and their values are
completely independent of the symbol that is bound to them (and that
symbol's specific position in the obarray, as well).  Why is
characterizing symbols by their obarray position important?

 > > The underlying objects that the symbols reference can be
 > > the same, whether they live in this module or another.
 > 
 > No.  This has horrible consequences (side effects) and isn't necessary
 > at all.  If you want to access symbols from a module that belongs to
 > the same package, use the "friend" declaration instead.

I could not find "friend" in either ice-9/*.scm or libguile/*.c.  It
seems to me that `reexport-from-module' is a form of that functionality,
and that we're not really talking about mechanism, but policy.  At which
point, everyone is free to not use something more powerful (dealing with
variables living in different modules) if they don't want to.

thi