Error Messages/46196
Example Error Message
- In the subscript expression x[...], the index in the first coordinate is implicit but the second coordinate (corresponding to J) explicitly specifies the index [J=....]. If you leave any index implicit, you must leave them all implicit. As it is, the J coordinate is ambiguous -- you might have intended to subscript on J, or you might have intended to subscript J on the result of an equality comparison.
Background -- Explicit vs implicit index naming
The Subscript operator is used to access a slice of a higher-dimensional array. The usual syntax is x[ J = v ]
. You specify the index explicitly, telling it that you want to obtain a slice or subscript over the index J
. This way, if other indexes are added to your model later, adding another index to x
, the subscript still operates on the correct index.
Consider this snippet where we declare x to be a local value:
Local x[I, J, K] := A+B Do
x[ K='banana', I='a', J=5 ]
Although A+B
might have more than 3 dimensions, within its lexical context, its declaration ensures that x
will have only three indexes -- I, J
and K
. Since the subscript on the second line again specifies each index explicitly, they order that the indexes are listed can differ from the order they were declared. However, since the indexes have been declared and an ordering of these indexes specified in the declaration for x
, it is a bit redundant to specify the index names again, especially if the index names happen to be long (which they aren't here). So save on characters in the expression, you can omit the index names, as long as you specify every coordinate and list them in the same order they were declared. So the previous expression is equivalent to
Local x[I, J, K] := A+B Do
x[ 'a', 5, 'banana' ]
Description of this error
You have mixed implicit index syntax and explicit index syntax in your subscript expression. This is similar to the following.
Background -- Explicit vs implicit index naming
The Subscript operator is used to access a slice of a higher-dimensional array. The usual syntax is x[ J = v ]
. You specify the index explicitly, telling it that you want to obtain a slice or subscript over the index J
. This way, if other indexes are added to your model later, adding another index to x
, the subscript still operates on the correct index.
Consider this snippet where we declare x to be a local value:
Local x[I, J, K] := A+B Do
x[ K='banana', I='a', J=5 ]
Although A+B
might have more than 3 dimensions, within its lexical context, its declaration ensures that x
will have only three indexes -- I, J
and K
. Since the subscript on the second line again specifies each index explicitly, they order that the indexes are listed can differ from the order they were declared. However, since the indexes have been declared and an ordering of these indexes specified in the declaration for x
, it is a bit redundant to specify the index names again, especially if the index names happen to be long (which they aren't here). So save on characters in the expression, you can omit the index names, as long as you specify every coordinate and list them in the same order they were declared. So the previous expression is equivalent to
Local x[I, J, K] := A+B Do
x[ 'a', J=5, 'banana' ]
There the subscript starts with the I
index implicit, which indicates that the remaining coordinates are expected to also have implicit indexes. However, the second coordinate appears to explicitly specify the index with J=5
. This mixing of implicit and explicit syntax is not allowed, and hence produces this error.
The ambiguity mentioned in the message comes from the fact that J=5
is a valid expression. It evaluates to 0 or 1. If you swapped the order and wrote 5=J
, then there would cease to be an ambiguity and it would be clear you intended to subscript on the result of the comparison.
Enable comment auto-refresher