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.

   return

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. Including a value denotes that the argument is optional and the value is used instead. Otherwise the corresponding argument is required.

Exit parameters only return a result. When you code a value then upon entry to the method the parameter is set to the value. Otherwise it is initialized to its default value. When the argument is omitted when called 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. There are several methods in the Phonecode sample program; including phonecode.g, load.dictionary.g, and encode.phone.g.

Function Procedure

Sequence Procedure