|
<< Click to Display Table of Contents >> Lookups |
![]() ![]()
|
Whenever a variable is encountered, a Lookup() method is called. As mentioned in the section on assignments, the method just looks for the variable in the available databank(s), but there are quite a lot of complications.
First, there is lookup on the LHS (left-hand side) and the RHS (right-hand side), and these are treated differently.
Next, lookups with indexers on the LHS are complicated, because the RHS is not assigned to a variable, but to some result of an indexing operation (like #m[1, 2]).
Also, lookups on the LHS have to deal with types: what to do if the RHS is a value (for instance an integer), and the LHS demands the result to become a string (like in the expression string %x = 100;). Should %x become the string '100', or should an exception be raised? This is dealt with regarding LHS lookups.
Conversions are explained in the main Gekko help system, in the Appendix, the section on "Assignments and types". The conversions depend upon whether there is a type indicator (like val %x = ...;), whether the left-side variable has a type symbol (like %x or #m), and otherwise there are different rules regarding what is allowed on the right-hand side if it is going to be assigned to a variable with a particular type indicator or type symbol. For instance, %x = #m; is allowed if #m is a 1x1 matrix (will assign it to the value %x).. And x = #m; is also allowed, if #m is either a list with a suitable number of elements of value type, or if #m is a nx1 matrix where n is suitable.