[Swift-user] Problem with scope and writability for complex types
Michael Wilde
wilde at mcs.anl.gov
Tue Jul 22 11:21:20 CDT 2008
This script compiles:
1 type file;
2
3 file fphr[];
4 file fpin[];
5 file fpsq[];
6
7 (file phr, file pin, file psq) formatdb (file input) {
8 app {
9 formatdb "-i" @input ;
10 }
11 }
12
13 file inputs[] <ext; exec="./inmapper">;
14
15 foreach f, i in inputs {
16 (fphr[i], fpin[i], fpsq[i]) = formatdb(f);
17 }
--- while this script gives a compile-time error:
1 type file;
2
3 type aux {
4 file phr;
5 file pin;
6 file psq;
7 };
8
9 (file phr, file pin, file psq) formatdb (file input) {
10 app {
11 formatdb "-i" @input ;
12 }
13 }
14
15 file inputs[] <ext; exec="./inmapper">;
16 aux a[];
17
18 foreach f, i in inputs {
19 (a[i].phr, a[i].pin, a[i].psq) = formatdb(f);
20 }
--- error is:
Could not start execution.
Compile error in foreach statement at line 18: Compile error in
procedure invocation at line 19: variable a is not writeable in this scope
---
It seems that the second script should be valid. Both set global
variables from with a foreach() in global scope.
When the variable is of complex type "array of file" the variable
indices seem to be writable.
When the variable is of complex type "array of struct of file" the
indexed struct fields seem not to be writable.
More information about the Swift-user
mailing list