This is the mail archive of the
mailing list for the Guile project.
Re: Reintroducing old `defined?'
Mikael Djurfeldt <firstname.lastname@example.org> writes:
> that Jim's proposal was about top-level environments strictly. I'm
> not sure it's a good idea to introduce an API for local environments
> (those created by lambda and let).
Yes. The new environment code doesn't support local environments
anymore. (-> ftp.tfh-berlin.de/pub/incoming/guile-environment-hack.tar.gz)
However, the following code is from an old environment
implementation. It first checks the local and then the top level
scm_finite_environment_bound_p (e, s)
struct environment *environment = (struct environment*) SCM_CDAR(e);
local_alist = SCM_CDR(e);
for (env = local_alist; SCM_NIMP (env); env = SCM_CDR (env))
l = SCM_CAR (env);
for (fl = SCM_CAR (l); SCM_NIMP (fl); fl = SCM_CDR (fl))
if (SCM_NCONSP (fl))
if (fl == s)
return SCM_CDR (l);
l = SCM_CDR (l);
if (SCM_CAR (fl) == s)
return SCM_CAR (l);
scm_hash = SCM_HASHCODE (s);
vcell = scm_symbol_get_handle (environment->obarray, s, scm_hash);
if (SCM_IMP (vcell))
But I still think `eval' should evaluate expressions in any environment
you pass it:
guile> (let ((a 12)) (eval '(display a) (the-environment)) -> 12
guile> (let ((a 12) (b 13)) (let ((c 14)) (eval '(display (the-environment)) (the-environment))))
-> (#<finite environment> (c . 14) ((b a) 13 12))
So you could write a scheme macro that tries to find the binding in the
local environment list and then in the top level environment by calling
(environment-bound? (car (the-environment) 'c))
> easy to think that they are some kind of generic lexical environments.
Umm sorry, but what is a "lexical environment"?