Top Type Conversion Constraints
French French German German ItalianItalian SpanishSpanish PortuguesePortuguese JapaneseJapanese KoreanKorean ChineseChinese

Mode Coercion



When a variable of one mode is given in a position where a variable of another mode is expected, mode coercion goes on in much the same way as type coercion does.

There are two basic places in which mode coercion happens: in identity formulas and in predicate calls. In the descriptions that follow, we assume that all necessary type conversion has already taken place.

Identities

In processing the identity formula a = b, the action actually performed depends on the modes of the terms a and b. For the purposes of the following table, we can consider output variables after their first assignment as input variables.

Any full-value term (any term made up only of constant terms, input variables, initialized output variables, initialized input/output variables, and symbolic variables whose values are fixed as full-value terms) can also be considered an input variable.

The operation of "backtracking out" a variable a is possible when the type of a has a small finite number of elements (i.e., an enumerated type, a subrange type with fixed upper and lower bounds, or a finite array type etc,); or when a is a symbolic variable of some other integral type (L, I, or a non-fixed subrange type) which is constrained to be in a small finite range.

If the system attempts to backtrack out a variable and fails, it raises the "too many backtracks" run-time error.

Predicate Calls

We can illustrate the mode coercion actions associated with predicate calls by a simple example. We have a predicate declared by
class P(x mode T) iff ...
where class is pred, proc, or subr, as appropriate, and mode is the mode of the parameter x. Given a call to this predicate, P(y), what action is actually performed by the call?

Mode coercion on predicate calls table:

Mode of x (parameter) Mode of y (parameter) Action performed
input input P(y)
input output z :> T & z = y & P(z)
input symbolic z :> T & z = y & P(z)
input i/o z :> T & z = y & P(z)
output input z :> T& P(z) & y = z
output output P(y)
output symbolic z :> T & P(z) & y = z
output i/o z :> T & P(z) & y := z
symbolic input z :: T & z = y & P(z)
symbolic output z :: T & P(z) & y = z
symbolic symbolic P(y)
symbolic i/o z :: T& z = y & P(z)
i/o input z :. T & z = y & P(z)
i/o output z :. T & z := y & P(z)
i/o symbolic z :. & z := y & P(z)
i/o i/o P(y)

Mode coercion on predicate table summarizes these actions. Usually, if the modes do not agree an auxiliary variable of the correct mode is implicitly declared. Most of the work of mode coercion is then passed off to the mechanism for resolving identity formulas (see previous section). The identity formula is computed either before or after the predicate call with the auxiliary variable, as appropriate.



Top Type Conversion Constraints