This is the mail archive of the guile@cygnus.com 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: Reintroducing old `defined?'


Mikael Djurfeldt <mdj@nada.kth.se> 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
bindings:

--------------------

SCM
scm_finite_environment_bound_p (e, s)
     SCM e;
     SCM s;
{
  SCM env;
  SCM vcell;
  SCM local_alist;
  scm_sizet scm_hash;

  struct environment *environment = (struct environment*) SCM_CDAR(e);
  local_alist = SCM_CDR(e);


  for (env = local_alist; SCM_NIMP (env); env = SCM_CDR (env))
    {
      SCM fl;
      SCM l;

      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);
		}
	      else 
		break;
	    }
	  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))
    {
      return SCM_BOOL_F;
    }
  
  return SCM_CDR(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"?

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