During the conversion of a program of mine to Pike I discovered that a
constant which was initialized by a sum of other constants got a wrong
value. I supposed the order of the definitions was relevant, I
rearranged them and that specific problem was fixed.
Then I did some tests in order to confirm the problem, and finally I
deduct the limitation is two nesting levels of forward definitions. Is
it right? I found nothing specific on `constant` in the documentation.
```
// XXX wrong
constant EXPECTED_15 = BOARD_Y + BOARD_BOTTOM_Y + 4;
constant BOARD_BOTTOM_Y = BOARD_HEIGHT + 1;
constant BOARD_HEIGHT = 5;
constant BOARD_Y = 5;
// ok
constant EXPECTED_2 = TWO;
constant TWO = 2;
// XXX wrong
constant EXPECTED_3 = THREE;
constant THREE = PAIR + 1;
constant PAIR = 2;
// ok
constant EXPECTED_14 = FOUR + TEN ;
constant FOUR = 4;
constant TEN = 10;
// XXX wrong
constant EXPECTED_5 = N6 - N1;
constant N6 = 4 + N1 + N1; // 6, ok
constant N1 = 1; // ok
// XXX wrong
constant EXPECTED_12 = N9 + N3;
constant N3 = 3;
constant N9 = 4 + N5;
constant N5 = 5;
// ok
constant EXPECTED_012 = N09 + N03;
constant N03 = 3;
constant N05 = 5;
constant N09 = 4 + N05;
void main() {
write("EXPECTED_15 = %d \n", EXPECTED_15); // result: 9 XXX wrong
write("EXPECTED_2 = %d\n", EXPECTED_2); // ok
write("EXPECTED_3 = %d\n", EXPECTED_3); // result: 0 XXX wrong
write("EXPECTED_14 = %d\n", EXPECTED_14); // ok
write("EXPECTED_5 = %d\n", EXPECTED_5); // result: -1 XXX wrong
write("N6= %d\n", N6); // ok
write("N1= %d\n", N1); // ok
write("EXPECTED_12= %d\n", EXPECTED_12); // result: 3 XXX wrong
write("EXPECTED_012= %d\n", EXPECTED_012); // ok
}
```
--
Marcos Cruz
http://programandala.net