Message-ID: <39C3A6C3.8F3B865A@attglobal.net>
Date: Sat, 16 Sep 2000 09:58:42 -0700
From: Chip Hayes <jwhayes@attglobal.net>
X-Mailer: Mozilla 4.72 (Macintosh; U; PPC)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: rec.arts.int-fiction
Subject: [Inform] ValueOrRun Question
Content-Type: text/plain; charset=us-ascii; x-mac-type="54455854"; x-mac-creator="4D4F5353"
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 32.101.147.203
X-Trace: 16 Sep 2000 17:05:35 GMT, 32.101.147.203
Organization: Global Network Services - Remote Access Mail & News Services
Lines: 45
X-Complaints-To: abuse@prserv.net
Path: news.duke.edu!newsgate.duke.edu!nntp-out.monmouth.com!newspeer.monmouth.com!europa.netcrusader.net!152.163.239.131!portc03.blue.aol.com!cpk-news-hub1.bbnplanet.com!news.gtei.net!newsfeed.us.ibm.net!ibm.net!news1.prserv.net!32.101.147.203
Xref: news.duke.edu rec.arts.int-fiction:78810

Can someone explain to me the mechanics behind the library routine
ValueOrRun()?

I know that it works all right... if obj.prop is a value, it returns
it.  If a routine it runs it.
I just want to know how it does this, considering how it's written.  It
reads:

[ ValueOrRun obj prop;
  if (obj.prop < 256) return obj.prop;
  return RunRoutines(obj, prop);
];

Even if the property in question is an integer  >255, the routine will
still properly return the value.  So what is the if statement testing
for?  Address?  The byte sized test must be clue, but I can't figure it
out.

If anyone cares, this came about when I discovered that some old code
(originally lifted from thief.inf) which used ValueOrRun(), was not
working under the newer compiler/library.  Granted, it was not being
used properly, as it was being used to test for an object number or
routine instead of value (a door_to property to be specific), and, when
it came across a routine instead of a room number, would return the
address of that routine instead of running it, making a confusing mess
of things.  I guess that used to work properly under an old version.
I'm not sure what was changed since the old library which was used to
implement thief.inf, but something sure did .  Anyway, for those times
when you need to return an object number or a routine, as opposed to a
value, this seems to have fixed it:

[ ObjectOrRun obj prop;
 switch (zRegion(obj.prop))
 {
    0, 3: rfalse;
   1: return obj.prop;
   2: return RunRoutines(obj, prop);
 }
];

But that still didn't explain to me how/why ValueOrRun() works.  What's
the magic 255 testing for?

Chip Hayes

