A G2 procedure consists of four major parts:
![]() |
The formal syntax of a G2 procedure is:
procedure-name ( [argument: type ] [, ...] ) [ = ( type [, ...] ) ]
[local-name [, ...]: type [= value-expression]; ] ...
begin[statement-label:] statement [; ...]end
[on error(local-name)
[label:] statement [; ...]end]
procedure-name ( [argument: type ] [, ...] ) [ = ( type [, ...] ) ]
check-inventory-for-part (mixer1: class mixer, part: text) = (truth-value)
class when specifying an argument or return value is one of the most common errors in defining procedures. Notes attribute of every procedure that shares the name. Invoking the duplicated procedure invokes an arbitrarily selected instance of it. The selection may differ from one invocation to the next.Procedures used as methods can have duplicate names provided that the number of arguments differs in each method that shares a name, as described under Duplicate Methods.
Local Declarations Syntax
A procedure's argument definitions (if any) define local names to hold the arguments. Any additional local names needed in the procedure are defined in the local declarations section. If no additional local names are needed, the local declarations section is omitted.
[local-name [, ...]: type [= expression]; ] ...
integer, each with the initial value 0.
inventory, products-shipped, orders: integer = 0;
G2-VARIABLE, as described in Chapter 15, Variables and Parameters.
Variables and parameters can have initial values, but these are not the same as the initial values of local names. Be careful not to confuse the two meanings of "initial value." The context always clarifies which is intended.
Procedure Body Syntax
The procedure body contains one or more procedure statements, which specify the operations that the procedure performs. All of the statements in a procedure are enclosed in a begin-end block. The syntax is:
begin[statement-label:] statement [; ...]end
| Element | Description |
|---|---|
|
statement-label
|
An integer or symbol.
|
|
statement
|
Any of the actions described in Chapter 19, Actions, or any of the statements described in the Dictionary of Procedure Statements.
|
go to, as described under go to.
Statements
Every statement in a procedure is either an action statement or a procedure statement. An action statement specifies some action, using the same syntax that the action uses when specified in a rule. For information on the various actions that a procedure can contain, see Chapter 19, Actions.
Procedure statements make assignments, control the flow of execution, and do other things typical of statements in any computer language. The following table summarizes all G2 procedure statements. The Dictionary of Procedure Statements provides complete information about all procedure statements.
Error Handler Syntax
G2 provides error handlers. When errors occur, G2 searches for and invokes the error handler. The default error handler prints a message to the logbook describing the error. on error statement. The syntax is:
[on error(local-name)
[label:] statement [; ...]end]
on error. For information on all aspects of G2 error handling, see Chapter 41, Error Handling.
Comments
You can include comments within the text of a procedure body by enclosing comments within braces:
{This is a Comment }