Trying to iterate through a list passed as a parameter brings up a strange error where the I7 compiler succeeded, but the I6 compiler failed to compile the translated code. For example:
[code]To decide whether list iteration works on (L - a list of numbers):
repeat with n running through L:
say “check![line break]”;
Test is a room.[/code]
It works if you declare a local list variable and let it equal the parameter and then iterate through that, though. The error from the I6 compiler is:
I figured it was a translation problem, and I was going to report it, but then it occurred to me that since modifying parameters can be a bad idea in some contexts if you don’t know what you’re doing [is this true inform?], maybe I6 had some kind of compiler error to keep you from messing with the parameters (though this isn’t really changing anything), in which case it should be a [characteristically obfuscated ] error in I7, too. I guess it’s not really a major issue when there’s an easy workaround, though.
The list support code from the template layer is fairly bulky, so it only gets compiled into the project if a list is actually declared (either as a local or global variable, or a property). IIRC, this is also true of indexed text. When these features were added, I think Graham was worried that automatically including both of them would make zcode games of any size almost impossible to make.
Yeah, note that you don’t need to use the list or even create a list with the same kind of value as the phrases which use lists. Either of these will work in your code:
Dummy list is a list of text that varies.
A person has a list of text called the sayings.
This is inconvenient if you’re creating an extension with list processing code, but don’t want to add a dummy list just to get the thing to compile. In that case, just add in the missing template code by hand, which I’ve temporarily forgotten how to do – I’ll get back to you if someone else doesn’t chime in first.
If the I6 compiler fails to compile I7’s translated code, it is always an I7 bug. (Well, unless you’ve included some of your own I6 code in the project. Then it could be your fault.
In this case, it’s failing to realize that it needs to include the list template code. You should report it.
(It’s not a bug that will come up for most people, because if there’s any list defined in the game, the template code will be thrown in. You’re only hitting it because you define this “decide whether” phrase that’s never used.)
I6 uses call-by-value parameters, and it’s always safe to change them.
Ahh, I see - I compiled after writing a subroutine, but before writing the caller’s code, to check the syntax. Now that I’ve defined the caller (and its local list variables) it indeed does not need that extra list variable anymore.