|
|
Bugzilla Link |
914 |
Created on |
Feb 21, 2012 20:07 |
Version |
1.00beta |
OS |
Linux |
Architecture |
Other |
Reporter |
snowgoon2003 |
Extended Description
From Bodos mail in the tread "using fold on vectors in a matrix"
----------------*****------------------------------
If you write something like this:
use Array: all;
int[.] american(int[.] a, int[.] b){
StdIO::print(b);
return (b);
}
int main()
{
a = [1,2,3,4,5,6];
c = american( a, a);
return( 0);
}
Then, in principle, you might think that print is just a side effect.
But no, in reality, SaC is very much aware of these things and print
operates on a global object named TheTerminal.
As a consequence, the compiler makes this explicit by converting the code into:
use Array: all;
int[.], Terminal american(int[.] a, int[.] b, Terminal TheTerminal){
TheTerminal' = StdIO::print(b, TheTerminal);
return (b, TheTerminal');
}
int, Terminal main(Terminal TheTerminal)
{
a = [1,2,3,4,5,6];
c, TheTerminal' = american( a, a, TheTerminal);
return( 0, TheTerminal');
}
This works fine as long as both sides, the function definition AND the function call are
being modified consistently.
Now, by using american within the fold operation, the function call is implicit, at least
in the beginning. Later in the compiler, we make it explicit. Seemingly, at that stage,
we have forgotten that we may have to adjust the call by any potentially affected objects :-((((
As a consequence, the compiler looks for a function american that only has two parameters,
which, at that stage no longer exists as the signature of american has been expanded into 3
arguments!