[Coldstuff] Environment list and recursive locations...

Brandon Gillespie coldstuff@cold.org
Fri, 15 Feb 2002 16:23:04 -0700


For kicks and grins I am including the code for the two variants...
Perhaps somebody can come up with a faster way of doing #2...

------------ #2 style

@program $foundation._environment2
  arg e;

  return #[[this(),1]];
.
@program $location._environment2() +access=pub
  arg e;
  var o,i;
  e = pass(e);
  for o in (.contents()) {
      if (!dict_contains(e,o)) {
          e = dict_union(e,o._environment2(e));
      }
  }
  return e;
.
@program $located._environment2() +access=pub
  arg e;
  e = dict_union(e, pass(e));
  if (!dict_contains(e, location)) {
      return dict_union(e, location._environment2(e));
  }
  return e;
.
@program $foundation.environment2
  return dict_keys(._environment2(#[]));
.

------------ #3 style

@program $foundation.environment3() +access=pub
  return [];
.
@program $location.environment3() +access=pub
  var o, e;
  e = [this()];

  for o in (.contents()) {
      if (o.has_ancestor($located_location)) {
          e += o.contents();
      }
      e += [o];
  }
  return e;
.
@program $located.environment3() +access=pub
  var o, e;

  return [this()] + setremove(location.environment3(), this());
.