From 353793082f9566a8c546b339386e437e689d6478 Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Thu, 24 Apr 1997 09:24:03 +0000 Subject: [PATCH] =?UTF-8?q?Functions=20for=20finding=20variable=20bindings?= =?UTF-8?q?,=20grace=20=C3=A0=20Tim=20Pierce.=20*=20gh=5Fdata.c=20(gh=5Flo?= =?UTF-8?q?okup,=20gh=5Fmodule=5Flookup):=20New=20functions.=20*=20gh.h=20?= =?UTF-8?q?(gh=5Flookup,=20gh=5Fmodule=5Flookup):=20New=20prototypes.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libguile/gh.h | 3 +++ libguile/gh_data.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/libguile/gh.h b/libguile/gh.h index 890b48883..94d575e52 100644 --- a/libguile/gh.h +++ b/libguile/gh.h @@ -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); diff --git a/libguile/gh_data.c b/libguile/gh_data.c index 3e1250c5e..b70228d8f 100644 --- a/libguile/gh_data.c +++ b/libguile/gh_data.c @@ -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; +}