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] |
> 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) */
[...]
> What do you mean by group? What do you mean by qualify?
Umm well a module is just like a country that a) protects its citizens and
b) makes sure that every citizen has a unique identification number.
> A module system's main job is to associate a reference (symbol in some
> usage context) to some object somewhere, w/ usage context including
> things like "current" name space and whether or not the particular
> object is fluid. All symbols are in fact different from each other, but
> only in name.
Okay.
> 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.
Jost