I just ran into this quirk, and wonder if anyone who understands the underlying I6 better than I do can explain whether it’s a “bug” or a “feature” … and more importantly, if there is a way to get around it. What happens in a nutshell is that “printing the name” rules are firing, not once, but twice whenever an object name is being printed up with either the definite or indefinite article. (Proper-named things don’t appear to be affected.) This means in particular that any printing the name rules with side effects can and do produce unexpected results.
If you find this hard to believe – believe me, so did I – please read on, because you can’t detect the double-invocation simply by whatever a “printing the name” rule prints up. Evidently one of these two passes doesn’t actually print any output! However it’s quite easy to verify that the rules are being hit twice, and not just once.
The following I7 code demonstrates the behavior:
[code]“Print Rule Quirk Demo” by Taryn Michelle
[Demonstrating that some I6 print rules trigger ‘printing the name of’ activity 2x per object printed!]
[First, a place to track the times we hit a rule for an object]
A rule-counter is a kind of object.
A rule-counter has a number called before-count. before-count of a rule-counter is usually 0.
A rule-counter has a number called for-count. for-count of a rule-counter is usually 0.
A rule-counter has a number called after-count. after-count of a rule-counter is usually 0.
A thing has a rule-counter called print-counter.
A thing has a number called the examine-count. The examine-count of a thing is usually 0.
[Now let’s check how many times ‘printing the name’ rules are hit for each object; also, we’re going to see from the results that the --> <-- we put around a printed object name appear only once EVEN IN CASES WHERE THIS RULE FIRES TWICE PER PRINT of the object. This illustrates why it was not possible to detect the “double-rule-activation” simply by adding debug output to the rules. We need to count hits to show what’s happening.]
before printing the name of something (called the target):
say “–>”;
if the print-counter of the target is not nothing:
increase before-count of the print-counter of the target by 1.
for printing the name of something (called the target):
if the print-counter of the target is not nothing:
increase for-count of the print-counter of the target by 1;
make no decision.
after printing the name of something (called the target):
say “<–”;
if the print-counter of the target is not nothing:
increase after-count of the print-counter of the target by 1.
[Try calling one of the print rules directly - to confirm it has the same behavior as when the underling inform does “print () obj.” ]
To say special-the (item - a thing): (- DefArt({item}); -).
the Chamber of Proof is a room. “[chamber-description]”;
To say chamber-description:
say “Wherein we shall demonstrate [the awful quirkiness] implicit in I6’s underlying use of ‘print rules’…[line break][an articulate thing] is double-counted when ‘said’ by the normal rules – these translate in I6 into something like ‘print (a) obj’; [paragraph break]”;
say “whereas [inarticulated] (said with no article, definite or indefinite) is not – the I6 translation here is ‘print (name) obj’. [paragraph break]”;
say “Finally, taking [special-the direct approach] we print the article by calling the print rule directly using ‘DefArt/IndefArt (obj)’ instead of ‘print (a)/(the) obj’.[paragraph break]”;
say “We use --> <-- to mark printing the name of objects (1) to make it clear to see how many times they’ve actually been printed in the text, but also (2) to demonstrate, despite triggering the ‘printing the name’ rules twice, while the ‘side effects’ happen every time (i.e., double-counting in our example), anything actually printed from within the rules only occurs once, thus internally output must somehow be suppressed the other time. [paragraph break]”;
say “Lastly, the objects printed out below by the ‘listing nondescript items’ activity again manifest the same behavior, which is unsurprising, since the underlying I6 list-printing code also ends up at some form of ‘print () obj;’[line break]”;
[Now scatter some things about to be printed in various ways]
the printery is a thing in the Chamber of Proof.
printery-counter is a rule-counter. the print-counter of the printery is printery-counter.
in the chamber is a thing called The Decidedly Proper Thing.
proper-counter is a rule-counter. the print-counter of the proper thing is proper-counter.
In the chamber is a thing called an articulate thing. The articulate thing is scenery.
articulate-counter is a rule-counter. the print-counter of the articulate thing is articulate-counter.
In the chamber is a thing called something inarticulated. something inarticulated is scenery.
inarticulate-counter is a rule-counter. the print-counter of something inarticulated is inarticulate-counter.
the awful quirkiness is scenery in the chamber.
quirkiness-counter is a rule-counter. the print-counter of the awful quirkiness is quirkiness-counter.
the direct approach is scenery in the chamber.
direct-counter is a rule-counter. the print-counter of the direct approach is direct-counter.
[And now some output to illustrate what’s going on. After every “look” or “examine” most of the objects printed up will have triggered their “printing the name” rules, not once, but twice. Only objects that are proper-named – i.e., which under the covers are firing off the (name) rule, and not one of the rules to print an article – have the normal count we would have expected (that is, once per time displayed).]
look-count is a number that varies. look-count is 0.
To say rule count of (target - a thing):
say “<[printed name of target]>”;
if the print-counter of target is nothing:
say " does not support ‘printing the name’ rule counting.";
stop;
say “has been looked at [look-count] time(s) and examined [examine-count of the target] times. It has triggered ‘printing the name’ rules [before-count of print-counter of target], [for-count of print-counter of target] and [after-count of print-counter of target] times (before, for and after)”;
after looking:
increase look-count by 1;
repeat with item running through things in the chamber:
say “[rule count of item].”;
after examining something (called the item):
increase the examine-count of the item by 1;
say “[rule count of item].”;[/code]
I’m using what I think is the latest build, 6G60. If you’ve got any clue what’s going on, thanks in advance for taking the time to share!
– Taryn