Overview
A Function is a named sequence of operations that compute and return a value. Functions and procedures are similar in many ways, but G2 invokes them differently, and they have different advantages and disadvantages.
Invoking Functions
G2 executes a function when the function's name and arguments (if any) appear as part of an expression that G2 is evaluating. The function executes synchronously, and the value that it returns is used just as if it had appeared literally at the point of the invocation. A function reference can appear in any statement at any point where a literal value of the type returned by the function could appear.
By contrast, a procedure executes only when a reference to it appears in a call statement or a start action; executes synchronously when called and asynchronously when started; and may or may not return a value.
For information on procedures, see Chapter 21, Procedures.
Executing Functions
A function executes exactly as if the body of the function appeared literally at the point of invocation. Therefore:
For information on execution time and timeouts, see Limiting Procedure Execution Time and Setting the Timeout Interval for a Rule.
Types of Functions
G2 provides three kinds of functions:
You can also invoke functions that run outside G2, as described in Chapter 53, Foreign Functions.
Copyright © 1997 Gensym Corporation, Inc.