[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Environments, modules, ....
From: |
Chris Cramer |
Subject: |
Re: Environments, modules, .... |
Date: |
Thu, 6 Sep 2001 15:05:41 -0500 |
User-agent: |
Mutt/1.2.5i |
On Thu, Sep 06, 2001 at 03:05:51PM +0200, Frederick Ros wrote:
> In a C program, I'd like to iterate through the list of all known symbol
> in the current environment.
This is a little difficult in C, but see below.
> Looking at the libguile code, I've been able to find that an
> scm_c_environment_fold function was available, that allow me to apply a
> function to each of the symbol bound in the given environment....
>
> The problem is how to get this environment ....
>
> I found some macros (SCM_ENV), or functions (scm_top_level_env), but the
> SCM they return seems to not fit (scm_c_environment_fold complains that
> this is not an environment..)
Unless I'm mistaken, the code in environments.c isn't actually in use yet.
So, I think what you really want to do is search the current module.
> My question is : Can someone provide me with a very short code example,
> or with some pointers in order to be able to get the current
> environment, and to print each of the bound symbol...
(module-search
(lambda (module v)
(module-for-each
(lambda (sym var)
(display sym)
(newline))
module)
#f)
(current-module)
#t)
In C, I suppose you could do something like:
void
list_symbols(SCM module, SCM outp)
{
SCM obarray;
int i, len;
SCM x;
obarray = SCM_MODULE_OBARRAY(module);
len = SCM_VECTOR_LENGTH(obarray);
for (i = 0; i < len; i++) {
for (x = SCM_VELTS(obarray)[i]; !SCM_NULLP(x); x = SCM_CDR(x))
scm_display(SCM_CAR(x), outp);
}
x = SCM_MODULE_USES(module);
for (x = SCM_MODULE_USES(module); !SCM_NULLP(x); x = SCM_CDR(x))
list_symbols(SCM_CAR(x), outp);
}
and then do list_symbols(scm_current_module(), scm_current_output_port()).
It seems like there should be an easier way, but I couldn't find it.
--
C. Ray C. aka Christopher Cramer
address@hidden
http://www.pyro.net/~crayc/