Newsgroups: rec.arts.int-fiction
Path: nntp.gmd.de!Dortmund.Germany.EU.net!main.Germany.EU.net!Frankfurt.Germany.EU.net!howland.erols.net!netcom.com!erkyrath
From: erkyrath@netcom.com (Andrew Plotkin)
Subject: Re: INFORM: Destructively looping through child objects?
Message-ID: <erkyrathDwKCAz.1C2@netcom.com>
Organization: NETCOM On-line Communication Services (408 261-4700 guest)
X-Newsreader: TIN [version 1.2 PL1]
References: <slrn51p5p5.10.baum@butternut.nist.gov>
Date: Thu, 22 Aug 1996 23:37:47 GMT
Lines: 39
Sender: erkyrath@netcom16.netcom.com

Michael Baum (baum@butternut.nist.gov) wrote:
> So I quotes from the INFORM Designer's Manual:

> > WARNING
> > When looping through the object tree, be careful if you are
> > altering it at the same time.
>
> This is all well and good, but I need to _selectively_ modify
> the tree, along the lines of:
>
>   objectloop (x in rucksack) {
>      if (x has evanescent) remove x;
>      }
>
> You see the issue. The approach of working through the
> while (child() ~= 0) goes into an infinite loop the first
> time it hits an object that fails the evanescent test.

The world is a bunch of linked lists, and you can get at the linkages 
using the "eldest" and "younger" functions.

x = eldest(rucksack);
while (x ~= nothing) {
  if (x has evanescent) {
    y = x;
    x = younger(x);
    remove y;
  }
  else {
    x = younger(x);
  }
}

--Z

-- 

"And Aholibamah bare Jeush, and Jaalam, and Korah: these were the
borogoves..."
