Method Procedure

Side effects are allowed in Methods, but you can also restricted them by using the Pure or Safe keyword. A Pure method cannot modify global variables nor perform input or output operations, or raise exceptions, but they can catch exceptions. Unlike functions they can have multiple Exit parameters and Change parameters whose arguments are intended to be modified. A Safe method is only restricted in that it cannot raise managed exceptions.

   method  NAME  [pure | safe]:          :A pure, safe, or unrestricted method.

    entry Parameter [= Value] Type, ...  :Input only parameters

   change Parameter [= Value] Type, ...  :Input and output parameters

     exit Parameter [= Value] Type, ...  :Output parameters

       :  Additional declarations and then executable statements go here.


Method calls are coded using subroutine notation. Optionally Entry, Change, and Exit parameters can be declared to determine how the arguments are processed.

   METHOD_NAME  [Argument, ... ];          Subroutine syntax.

When you declare an Entry parameter, its argument can not be modified. Arguments for Change parameters are intended to be modified by the method. Declaring a parameter with a value denotes that an argument is optional and the value is used when none is given. With no value a corresponding argument is required.

Exit parameters only return a result. When you declare an Exit parameter value then upon entry to the method the parameter is initialized the value. Otherwise it is initialized to its default value for its type. When the calling argument is omitted then the return value is discarded. Exit arguments may be omitted whether or not an initial value is coded.

You can place the different parameter declarations in any order and there can be multiple declarations of each kind. Multiple parameters can also be listed on each declaration. For examples of parameter usage there are several methods in the Phonecode sample program; including phonecode.g, load.dictionary.g, and

Function Procedure

Sequence Procedure