Newsgroups: rec.arts.int-fiction
Path: nntp.gmd.de!news.ruhr-uni-bochum.de!news.rwth-aachen.de!news-koe1.dfn.de!news.k.shuttle.de!news.b.shuttle.de!news-ber1.dfn.de!fu-berlin.de!nntp.zit.th-darmstadt.de!voskovec.radio.cz!www.nntp.primenet.com!nntp.primenet.com!feed1.news.erols.com!howland.erols.net!netcom.com!erkyrath
From: erkyrath@netcom.com (Andrew Plotkin)
Subject: Re: Inform 6 problem: Objectloop
Message-ID: <erkyrathE17II7.EHM@netcom.com>
Organization: NETCOM On-line Communication Services (408 261-4700 guest)
X-Newsreader: TIN [version 1.2 PL1]
References: <57052r$5so@bertrand.ccs.carleton.ca>
Date: Thu, 21 Nov 1996 06:10:55 GMT
Lines: 56
Sender: erkyrath@netcom16.netcom.com

Pat Wigfull (pwigfull@superior.carleton.ca) wrote:

> I don't know if this has been discussed before, but I noticed that Inform
> 6 has problems with the objectloop statement, contrary to the designer's
> manual.

> While a command like:

> 	objectloop (x in Drawing_Room) print (name)x;

> works fine, the example given in the Designer's manual of:

> 	objectloop (x ofclass Bird) move x to Aviary;

> will not work.

> Thus, I had a line like this:
> 	objectloop (x in Airlock) remove x;

> Simple, yes, and similar to the Aviary example above. 

Simple, yes, similar, no. The Aviary example is legal, but your code is 
not, because the condition gets mangled halfway through. That is, the set 
of objects x such that "x in Airlock" is true gets changed in the course 
of the loop. You must expect that this will screw up the loop code.

In contrast, the set of objects x such that "x ofclass Bird" never 
changes. Hm. Actually, it might, if you're dynamically deleting the bird 
objects in the loop. Dangerous stuff! Don't do it.

> Is this a problem that may be rectified in future Inform releases?

There really is no way to do this, not without consuming a lot more memory
and time. It necessarily must follow the object tree's links to do an "x
in y" condition, and if the object tree is changing at the same time, it
won't be smart enough to keep up. 

(Consider an analogy: if you wrote a loop such as
  for (i=0 : i<10 : i++) { i = 4; }
it would not execute exactly ten times. This is not a bug in the compiler; 
it's an inevitable result of shooting yourself in the foot. Like C, 
Inform is powerful enough to target your foot.)

To answer your actual question, yes, there is a canonical idiom for 
moving all of the contents of object a to object b. The following is safe:

while (child(a) ~= nothing) {
  move child(a) to b;
}

--Z

-- 

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