| Prev | Next | Start of Chapter | End of Chapter | Contents | Index | (10 out of 12)

Evaluating Expressions in Attributes

In several blocks, you can set an attribute to an expression that the block will evaluate later. You must enclose the expression to evaluate in brackets and quotes ("[expr]"). For example, you could set the Name of Sensor attribute of an Entry Point to "[the temp of tank1]", where tank1 is an object with the variable or parameter attribute temp.

This section lists the attributes that contain expressions, describes the type of expressions they may contain, and shows examples of some diagrams that use this feature.


Note: If you use expressions in attributes, NOL evaluates the expression at run- time each time the block evaluates, which degrades performance.
These attributes can contain an expression that evaluates to a G2 variable or parameter, such as "[the volume of mixing-tank-3]":

These attributes can contain an expression that evaluates to a symbol that names a graph or chart:

This attribute can contain an expression that returns a truth value:


Note: In the values of these attributes, include brackets only if the brackets are enclosing an expression. Any other use of brackets could cause an error.
You cannot include any arbitrary G2 expression in these G2 attributes. The table below lists the bracketed expressions that attributes can contain:

This expression Is And is replaced by
[object-name]
The name of a G2 variable or parameter.
The value of the G2 variable or parameter.
[attr-name]
An attribute in this block.
The value of the attribute.
[the attr-name of
object-name]

An attribute in the named object.
The value of the attribute.
[the attr-name of the superior object]
An attribute in the object that owns the subworkspace that contains this block.
The value of the attribute.
[the superior object]
The object that owns the subworkspace that contains this block.
The object.
[ (g2-expression) ]
Any G2 expression you can use in a G2 formula.
The value of the expression.
[(call function
g2-function)]

A call of a G2 function.
The value of the function.
[(call procedure g2-procedure)]
A call of a G2 procedure.
The return value of the procedure.

Note that object-name can be the name of any named G2 object, and attr-name can be any user-defined attribute or the system attribute name. The syntax for g2-expression, g2-function, and g2-procedure is discussed in the sections below.

Using a G2 Expression

When you use a string of the form "[(g2-expression)]", you can use many G2 expressions in the attribute. NOL evaluates the expression and replaces it with the value returned.

To refer to the block that contains the attribute, your expression can use the term the item.


Note: You must enter the expression the item with a single space between the two words. If it contains a tab, line feed, or more than one space, NOL will not recognize it.
When you run your application in a run-time or restricted use G2, you cannot use a string of the form "[(g2-expression])". Instead, create a new function or procedure that contains that expression and use a string of the form
"[(call function g2-function)]" or "[(call procedure g2-procedure)]".

Using a G2 Function or Procedure

With a string of the form "[(call function g2-function)]" or "[(call procedure
g2-procedure)]", you can call any function or procedure from the attribute. Unlike using a G2 expression, you can call a function or procedure when your application is running in a run-time or restricted use G2.

The function or procedure must take one argument which will be the block that contains the attribute, and must return either a string or a variable or parameter, depending on what attribute it is used with.

This is the format for a function:

This is the format for a procedure:

Examples

The picture below shows an Entry Point that uses an expression for the Name of Sensor. The expression refers to the volume of Tank-1, which is an attribute that is given by a variable class. The Data Source is external. The output data value for the entry point corresponds to the current value of the volume of the tank.


The following picture shows a tank object with a subworkspace. The subworkspace contains a NeurOn-Line diagram that reads the temperature and volume from the tank and tests whether those numbers fall within certain limits. If they're outside the limits, the NeurOn-Line diagram invokes the rules on the Rule Action block. Under each Entry Point appears the value of the attribute Name-of-sensor.


| Prev | Next | Start of Chapter | End of Chapter | Contents | Index | (10 out of 12)

Copyright © 1996, Gensym Corporation, Inc.