|
When do dollar commands occur? |
Top Previous Next |
|
One important consideration when considering employing $commands involves the timing of there resolution. Suppose we have a file (toinclude.gms) that contains
a=3;
and a file that includes this file but also redefines it via use of put commands and in the sequence as typed the redefinition occurs before the inclusion as follows (timeinclude.gms)
scalar a /1/; file toinc /toinclude.gms/; put toinc,'a=5;' /; $include toinclude display a;
so that after the program runs the file (toinclude.gms) contains
a=5;
So what does the display look like? Well it is
6 PARAMETER a = 3.000
reflecting the initial value of the parameter "a" from toinclude.gms before the program started, and is unaffected by the action of the put command. Why? This occurs because all $ commands are resolved at compile time and can never be affected by the subsequent results of the program. Another example is also instructive as illustrated by the example dollartime.gms below.
where the resultant output is
---- 4 PARAMETER a i1 44.000, i2 33.000
---- 6 PARAMETER a i1 44.000, i2 33.000
Note in line 4 the value we get from the display is not the 22 entered originally for a(1) but is rather the redefined value allowed by $ONMULTI of 44 which does not actually occur until line 5. This occurs because the $ and redefinition is processed before the execution time display occurs. This can become yet more complex when one is using $CALL and GDX associated commands as illustrated in the Links to Other Programs Including Spreadsheets chapter. |