Error Messages/46194

Example error message

In the subscript expression with implicit indexes, x has 3 declared indexes but more than 3 expressions were given.

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 on this error

You have an expression such as

Local x[I, J, K] := A+B Do
x[ 'a', 5, 'banana', 'zebra' ]

Here x has 3 indexes but 4 coordinates were specified in the subscript.

Comments


You are not allowed to post comments.