A procedure can be either a Method, Function, or a Sequence. Methods are invoked using a subroutine call. A function is usually invoked within an expression, but you can use a subroutine call as well. Sequences are invoked either in a Sequence Do loop or a Churn command.
The first section of a procedure is the preamble which contains parameter and Local variable declarations and any preconditions. The first procedure declaration determines the kind of procdure and its name.
method Name [pure] function Name sequence Name [pure]
The optional 'pure' attribute on a Method or Sequence indicates that the procedure is free of side effects. Functions are always pure. Pure procedures can only invoked from other Pure procedures. They may not contain any Alter declarations or Input and Output commands. Any assertions can only raise fault exceptions; which generally do not occur in production code.
This is followed by Entry, Change, or Exit parameter declarations. An Entry parameter is an input to the procedure parameter that cannot be modified. A Change parameter is both an input and output and is intended to be modified. Exit parameters return results from a procedure.
entry Name = Default Type entry Name[ Dimensions ] Type change Name = Default Type change Name[ Dimensions ] Type exit Name = Initial Type exit Name[ Dimensions ] Type exit @Name Type exit @Name[ Dimensions ] Type
Scalar Entry and Change parameters can optionally declare a default value. The default is used when calling the procedure and the corresponding argument is ommitted. With no default the argument is required. For an Exit parameter, it is set to the initial value upon entry to the procedure.
Next come Local variable declarations and Use and Alter declarations to gain access to Global variables. Local variables are only used within the procedure and Global variables are declared in Class files. A Use declaration provides read only access to Global variables while Alter allows the procedure to modify them.
local Name = Initial Type local Name[ Dimensions ] Type use Class / Name ... alter Class / Name ...
Preconditions go last in a preamble. While they contain executable assertions they are also declarations. The signature of a procedure consists of the declarations a programmer needs to invoke the procedure - the kind of procedure, it's name, parameters, along with preconditions.
precondition Condition Context : .
Conditions in a precondition can only reference parameters and global variables. If the condition fails the Context clause sets up context information about the exception.