Parameters
The parameters are a list of parameters for the method. A parameter declaration has the following syntax.
name[, name, name...] : type [usage];
The usage value can be constant, input, io (input-output), or output. If you do not specify a usage, a default of constant is assumed.
The parameter usages are as follows.
-
For constant and input parameters, the parameter value specified in the method call is passed to the corresponding parameter in the called method.
You cannot assign to an input parameter.
-
For output parameters, the value is passed in the reverse direction, from the parameter of the called method back to the corresponding parameter of the caller.
This copying back of the parameter value occurs when the called method returns, following any epilog that may be defined.
-
For io parameters, the parameter value is passed in both directions, as follows.
-
From the caller to the called method when the method begins execution
-
From the called method back to the caller when it returns, following any epilog that may be defined
-
You can define parameters only for conditions that are not constraints, and the parameters must be constant parameters. (For more details, see "
For details about promoting a local variable to be a parameter of the current method, see "
As the name implies, constant parameters cannot be updated or modified in any way within the body of the method. Specifically, the following restrictions apply to constant parameters.
-
You cannot assign to the parameter.
-
You cannot assign to properties of the parameter object.
-
Updating methods cannot be invoked for the parameter.
-
Updating methods cannot be invoked for properties of the parameter object.
The following table lists the use of a primitive type parameter in a method.
Usage | Value Passed into Method | Parameter Value Can Be Updated in Method |
---|---|---|
constant | Yes | No |
input | Yes | Cannot be updated by assignment, but can be updated within an updating primitive type method by using the self system variable |
output | No | Yes |
io | Yes | Yes |
The following table lists the use of a parameter containing an object reference in a method.
Usage | Reference Passed into Method | Object Referenced By Parameter Can Be Updated | Parameter Can Be Assigned New Object Reference |
---|---|---|---|
constant | Yes | No | No |
input | Yes | Yes | No |
output | No | Not applicable | Yes |
io | Yes | Yes | Yes |
When a parameter is an object reference, the usage of a parameter also determines the type of reference that can be passed by using the parameter, as listed in the following table.
Usage | Types that Can Be Passed to Method | Reason |
---|---|---|
constant | Reference of the same type as the parameter or any of its subclasses | Equivalent to the calling method assigning a value to the parameter in the method being called |
input | Reference of the same type as the parameter or any of its subclasses | Equivalent to the calling method assigning a value to the parameter in the method being called |
output | Reference of the same type as the parameter or any of its superclasses | Equivalent to the method being called assigning a value to the variable in the calling method |
io | Reference passed must be of the same type as the parameter | Combination of input and output, so an exact match is required |
For details about pseudo types and passing variable parameters to methods, see "Pseudo Types" and "Passing Variable Parameters to Methods", respectively, later in this chapter.