| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (12 out of 14)

Variable and Parameter Expressions

These expressions refer to the knowledge associated with variables and parameters.

Expressions that refer only to the valid current value of a variable cause G2 to perform data seeking to obtain a new current value if the specified variable has never had a value or if its current value has expired.

A reference to a variable or parameter produces the same value everywhere it is used in the same expression. Also, a reference to a variable or parameter produces the same value everywhere it is used within the same transaction scope.

Directly Referring to a Variable or Parameter

To refer directly to a variable or a parameter:

Refer to a variable or parameter to produce its current value in a larger expression. If a variable has no current value, in some contexts, such as in rules and the collect data statement in procedures, G2 performs data seeking to attempt to obtain a new current value. See the discussion of data seeking in Obtaining Values for Variables.

For example, in a rule:

In this case, the Temperature attribute for the user-defined TANK class is defined as given by a variable. If the Temperature of tank-1 has a current value, the conclude action in the rule's consequent uses that value as the new value of the Latest-temperature attribute of master-display. If the Temperature of tank-1 does not have a current value, referencing it causes G2 to perform data seeking.

Since variables do not always have a value, you cannot refer to them directly in procedures as you can a parameter. Attempting to do so causes G2 to signal an error. Instead, you can access the value of a variable within a procedure by using a collect data statement or within a the current value of expression.

A collect data statement causes data seeking if the variable does not have current value. For more information about how G2 performs a collect data operation, see collect data.

Using the Value of Expression

To refer to the value of a variable:

This expression produces a valid current value of the specified variable. If its current value has expired, G2 performs data seeking to obtain a new current value. If an attempt at data seeking fails for any reason, evaluating this expression produces a no value condition.

The expiration time interval of this expression is the expiration time interval of the current value of the specified variable. For example:

Using the Has a Value Expression

To determine if a variable has a value:

This expression produces a truth-value that indicates whether a variable has a valid current value or whether G2's most recent attempt at obtaining a new current value succeeded. For example:

In this case, if the temperature of tank-1 has a valid current value, this expression produces the truth-value true. If the temperature of tank-1 has never had a value, or if its current value has expired, this expression causes G2 to perform data seeking to obtain a new current value. If G2 obtains a value from that data seeking, the expression produces the truth-value true, else the expression produces the truth-value false.

Using Current Value Expressions

A variable has a current value when it has a value that has not yet expired. Current value expressions do not cause data seeking, even if the specified variable has no current value.

When a variable receives a new current value, G2 determines an expiration time for that value based on whether it was explicitly specified (via the conclude ... with expiration action) or by combining the collection time of the new value and the variable's validity interval.

To obtain a variable's current value:

This expression refers to a variable's current value, but does not cause data seeking if the variable has never had a value or if its current value has expired. If the specified variable has a current value, this expression produces it. Otherwise, the expression produces a no value condition. For example:

If this expression produces a value, the expiration time of the expression is the expiration time of the current value. If this expression produces a no value condition, the expiration time is also a no value condition.

To determine whether a variable has a current value:

This expression produces a truth-value that indicates whether a variable has a current value. For example:

In this case, if the Temperature attribute of tank-1 has a current value, this expression produces the truth-value true. If the Temperature attribute of tank-1 has never had a value, or if its current value has expired, this expression produces the truth-value false.

If this expression produces the truth-value true, the expiration time of this expression is the expiration time of the current value. If this expression produces the truth-value false, the expiration time is indefinite.

If a has a value expression is nested within a has a current value expression, G2 evaluates the nested expression no differently than a has a value expression. G2 performs data seeking, if necessary, to obtain a new current value for the variable referenced in the nested has a value expression.

Obtaining the Simulated Value of a Variable or Parameter

The G2 Simulator is a superseded capability. For more information, see Appendix F, Superseded Practices.

Obtaining the Collection Time for a Variable or Parameter

To obtain the collection time for a variable or parameter:

This expression produces an integer value that represents the time in seconds when the specified variable or parameter received its most recent value. This time value is based on the G2 clock, so it might not represent the passage of real time.

If you specify this expression without the optional as of integer-expression datapoints ago phrase, for the expression to produce a value, the specified variable or parameter need not have a current value, but must have received at least one history value. Otherwise, this expression produces a no value condition. For example:

In this case, if the variable custom-variable has received at least one history value, this expression produces an integer value that represents the time in seconds at which the most recent history value was received.

If you specify this expression with the optional as of integer-expression datapoints ago phrase, then for the expression to produce a value, the specified variable or parameter need not have a current value, but must have received at least the specified number of history values plus one.

Otherwise, this expression produces a no value condition. The most recently received history value is zero (0) history values ago. For example:

If the variable custom-variable has received at least 11 history values, this expression produces an integer value that represents the time in seconds at which the value 10 history values ago was received.

Obtaining the Expiration Time for a Variable

To obtain a variable's expiration time:

This expression produces an integer value that represents the expiration time of the specified variable's most recently received history value. If the specified variable has never received a value, or if its Validity-interval attribute is set to indefinite, this expression produces a no value condition. For example:

In this case, if the variable custom-variable has received at least one history value, this expression produces an integer value that represents the time in seconds at which the variable's current value expires.

Referring to A Variable or Parameter that Gives the Value of an Attribute

To refer to a variable or parameter giving the value of an attribute:

This expression produces the child variable or parameter that gives the value of an attribute of an object, connection, or message of a user-defined class. This expression refers to the child variable or parameter as an item, rather than to the value of that variable or parameter. For example:

This expression refers to the Status attribute of the temperature-variable item that gives the value of the Temperature attribute of tank-1.

| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (12 out of 14)

Copyright © 1997 Gensym Corporation, Inc.