% procedures: search (a: array[int], x: int) returns (int) signals (not_found) combine (x: sequence[int]) returns (int) % an iterator: elements (a: array[int]) yields (int)Routine specifications have the following form:
<routine_interface> -> <proc_interface> | <iter_interface> <proc_interface> -> <idn> [<parms>] <formal_args> [<returns>] [<signals>] [<where>] <iter_interface> -> <idn> [<parms>] <formal_args> <yields> [<signals>] [<where>]The parms and where appear only if the routine is parameterized; we defer discussion of these forms to Section 9.3. The formal_args defines the formal arguments of the routine:
<formal_args> -> "(" [ <decl> ["," <decl>]* ] ")"The returns clause lists the types of the results of a procedure:
<returns> -> returns "(" <type_designator> ["," <type_designator>]* ")"There can be zero or more results, and the returns clause is omitted if there are no results. The yields clause lists the types of yielded items for an iterator:
<yields> -> yields "(" <type_designator> ["," <type_designator>]* ")"An iterator must always have a yields clause, and the yielded items must always contain at least one result. The signals clause lists the names and result types for the exceptions of the routine:
<signals> -> signals "(" <exception> ["," <exception>]* ")"where
<exception> -> <name> ["(" <type_designator> ["," <type_designator>]* ")"] <name> -> <idn>Each exception name must be distinct and none can be "failure"; in addition to the explicitly listed exceptions, every routine can raise the "failure" exception, with a single "string" result.
The type of a routine is derived from its routine_interface in a straightforward way: all the information in the interface is significant except for the routine name and the names of the formal arguments. For example, the type of the combine procedure shown above is "proc (sequence[int]) `returns` (int)", the type of the search procedure is "`proc` (array[int], int) `returns` (int) `signals` (not_found)", and the type of the elements iterator is "`iter` (array[int]) `yields` (int)". The "failure" exception does not appear in these types; it is suppressed because every routine has this exception.
The various routine types form a type hierarchy (3.4.1).
A routine whose last argument is a sequence can be called using a varying number of arguments in that position (6.1).