| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (3 out of 30)

Executing Actions

An action executes when control reaches it during execution of a procedure, rule, action button, or user menu choice. When more than one action appears in one of these contexts, the actions can execute sequentially or in parallel.

For sequential execution of a series of actions, G2 performs each statement in the order in which it appears. Thus the following three statements, executed sequentially, swap the values of var1 and var2:

For parallel execution of a series of actions, G2 first evaluates the arguments of every action, and then executes each action. Thus, the result of executing these actions in parallel:

is to swap the values, rather than to assign the value of var2 to both var1 and var2, which would happen if G2 executed the same statements sequentially.

The order in which G2 executes actions in parallel after evaluating their arguments is not predictable: G2 may order their execution as needed to optimize scheduling.

Executing Actions in Procedures

In a procedure, sequential execution is the default. Actions in a series therefore execute sequentially unless they appear in a do in parallel statement, as described under do in parallel.

Executing Actions in Other Contexts

In rules, action buttons, and user menu choices, parallel execution is the default. Actions in a series therefore execute in parallel unless they are qualified by an in order clause, as described under Specifying Sequential Execution.

Executing Iterative Actions

Sequential or parallel execution can also occur in the execution of a single action. If an action iterates over a class of items, such as:

G2 finds each item to which the action can be applied (in this case, every tire) and executes the action for each item it finds. If the action exists in a context where sequential execution applies, G2 applies the actions to the items sequentially. If the context specifies parallel execution, G2 applies the actions to all of the items in parallel.

For more information about parallel and sequential execution within rules, see Understanding Rule Invocation and Execution.

Further Information

The principles that govern the use of actions in rules apply to their use generally, as described in Chapter 23, Rules, Inferencing, and Chaining. For further information about specifying actions, see in that chapter:

| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (3 out of 30)

Copyright © 1997 Gensym Corporation, Inc.