This is the mail archive of the 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: gh_module_lookup(vec, *sname); How do I get vec?

>>>>> "Jost" == Jost Boekemeier <jostobfe@linux.zrz.TU-Berlin.DE> writes:

    Jost> I'm using my own version of guile and use the environment
    Jost> API to manipulate module bindings, but as far as I can tell
    Jost> the gh_* functions should always operate in(guile_user) and
    Jost> not in (guile).

This is certainly not the case with guile 1.4.  As I understand the
module and gh_* system (the info pages I have for the gh_ interface
are in '' and date to guile 1.2a. Althoug I believe at
one time it was FSF policy that all GNU software be distributed with
info pages I have been unable to find these in the guile 1.4 tarball)
you are in (guile) until you enter the repl with
"gh_repl(argc,argv)".  Once you do this there isn't any way to execute
gh_* functions directly, i.e. without being called indirectly through
a user intiated event in the repl.   Note the following "standard" way
of using the gh_ interface.

int main(int argc,char **argv) {
  gh_enter(argc, argv, main_prog);
void main_prog(int argc, char *argv[]) {
  gh_eval_str("(define test-module the-module)");  

[d3h486@wd29688 PatAyotte]$ ./wrap-guile
guile> test-module
#<module (guile) 300500a0>
guile> the-module
#<directory (guile-user) 3007d0f0>

My guess at how the module system works is based on experimentation
since I am unable to find formal documentation for it.

Namespaces are hierarchical, if a symbol is not found in the current
namespace it is looked for in the space above.

You can store a record which corresponds to a namespace in a variable.
This allows use of the (set-current-module module) function.  However
you have to keep track of the hierarchy when storing these values,
once you move to a higher module the variable in which you stored the
previous module is no longer visible.

The function (module-define! module name value) lets you define
symbols in arbitrary modules.  You need to use this to bind a symbol
for your current module e.g. (guile-user) if you set the current
module to one above, like 'the-root-module and then wish to get back.

I have been unable to find a function which maps names to modules.
resolve-module, which takes a list as it's argument, does not return
the same object for (resolve-module (list 'g 'u 'i 'l 'e)) as

I have not tried it yet, but it look like with some effort you can use
gh_module_lookup() to lookup symbols in specific modules.  However the
module argument is, I think, the obarray of the module, not the module
record which is passed around and handled by the scheme module
functions.  Since you are not in (guile-user), and I don't think the
module has been constructed, until you enter the repl, you can't get
the value you would need to access symbols in guile-user, or force
symbols to be created in guile-user until you enter the repl.  Once
there, you can't force C code to be run.  

Clearly the gh_lookup() in my code is doing it's lookup in the (guile)
namespace not the (guile-user) space.  This is confirmed by looking at
the code in gh_data.c.  The problem I have is that I don't know how to
get the SCM vec argument to gh_module_lookup() which would be required
so that lookups would take place in (guile-user).  Unless I'm
mistaken, the (guile-user) module has not been constructed before I
enter the gh_repl().


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