1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-29 16:30:19 +02:00

Functions for finding variable bindings, grace à Tim Pierce.

* gh_data.c (gh_lookup, gh_module_lookup): New functions.
* gh.h (gh_lookup, gh_module_lookup): New prototypes.
This commit is contained in:
Jim Blandy 1997-04-24 09:24:03 +00:00
parent 819f936bd9
commit 353793082f
2 changed files with 32 additions and 0 deletions

View file

@ -148,6 +148,9 @@ SCM gh_vset(SCM vec, SCM pos, SCM val);
SCM gh_vref(SCM vec, SCM pos);
unsigned long gh_vector_length(SCM v);
SCM gh_lookup (char *sname);
SCM gh_module_lookup (SCM vector, char *sname);
SCM gh_cons(SCM x, SCM y);
#define gh_list scm_listify
unsigned long gh_list_length(SCM l);

View file

@ -286,3 +286,32 @@ gh_vector_length (SCM v)
{
return gh_scm2ulong (scm_vector_length (v));
}
/* Data lookups between C and Scheme
Look up a symbol with a given name, and return the object to which
it is bound. gh_lookup examines the Guile top level, and
gh_module_lookup checks the module namespace specified by the
`vec' argument.
The return value is the Scheme object to which SNAME is bound, or
SCM_UNDEFINED if SNAME is not bound in the given context. [FIXME:
should this be SCM_UNSPECIFIED? Can a symbol ever legitimately be
bound to SCM_UNDEFINED or SCM_UNSPECIFIED? What is the difference?
-twp] */
SCM
gh_lookup (char *sname)
{
return gh_module_lookup (SCM_BOOL_F, sname);
}
SCM
gh_module_lookup (SCM vec, char *sname)
{
SCM sym = gh_symbol2scm (sname);
if ((scm_symbol_bound_p (vec, sym)) == SCM_BOOL_T)
return scm_symbol_binding (vec, sym);
else
return SCM_UNDEFINED;
}