After I thought I had a decent knowledge of I7, my biggest comeuppance was some basics about texts.
In 6G60, “text” and “indexed text” were separate types one had to convert between. Texts were strings that included adaptive text; indexed texts were plain text strings. In 6L02, they become one thing from a language user point of view while still having separate representations under the hood. In 6M62 and v10, one can still say “indexed text” but it means the same thing as “text”.
Texts containing adaptive texts are Schroedinger’s Boxes: their values are undefined until you open the box and the wave function collapses into some particular string. And that happens every time you open the box. So if you have:
pack-animal is a text that varies.
pack-animal is "[one of]mule[or]llama[cycling]".
when play begins:
say "'[pack-animal]' is [number of characters in pack-animal] characters long.";
you get "mule" is 5 characters long.
To pin it down, you need the substituted form of <text>
. The docs also refer to this as “expanding”, though that’s not the name of the phrase. I’ll use that term in the following.
If you try to compare two texts-with-adaptive-text with “is”, the result is almost always false even if their expanded forms are the same. If you have if t is empty
when t is a text-with-adaptive-text, the result is always false, even when the expanded text is empty. Comparing two plain texts with “is” works. Comparing a text-with-adaptive-text to a plain text works (the text-with-adaptive-text gets expanded). Thus the easiest way to test whether a text-with-adaptive-text is empty is if t is ""
.
So: don’t compare strings variables with “is”. If one side or the other is a text literal (“literal” is programmer-ese for not a variable, but some particular explicit value in your code, a quoted string in this case), e.g., if t is "cat"
you’re okay. Otherwise, stick to if t exactly matches the text w
.
To tell whether something is a plain text or a text-with-adaptive-text, you can use the substituted
or unsubstituted
adjectives.
To say
phrases can have any code, including code that has nothing to do with output. So there’s a sometimes clever trick where you sneak side-effects into saying things. But keep in mind that these side effects occur every time the text is expanded, not just when it’s output. So if you have:
g is initially 0.
To say gg: increment g; say g; say line break;
when play begins:
say gg;
if "[gg]" is "1", say "gg = 1.";
let q be the substituted form of "[gg]";
say gg;
the output is:
1
4