12.2.4 Value declarations

A function definition's value declaration follows the parameter list and is preceded by =>. The syntax of a value declaration is similar to that of a parameter list. If the function returns no values, the value declaration is an empty set of parentheses. Otherwise, the declaration can contain separate declarations for all returned values, separated by commas. Each of these individual declarations consists of a name and, optionally, :: followed by a type. The name does not specify a variable and has no use other than documentation. But the returned value that corresponds to the declaration must be of the declared type, or Dylan signals an error. The default return value type is <object>.

A value declaration can also end with #rest followed by a name and, optionally, :: and a type. This declaration indicates that the function can return any number of additional arguments, each of which must be of the specified type.

If a function has no explicit value declaration, the default declaration is (#rest x :: <object>). This declaration indicates that the function can return any number of arguments of any type.

The value declaration determines the number and types of values that the function returns, even if the last expression in the function's body returns a different number of values. If the function's body returns fewer values than are declared, the function defaults the remaining values to #f and returns them. (But if the value declaration specifies a type for any of these values, and if #f is not an instance of that type, Dylan signals an error.) If the function's body returns more values than are declared, the function returns the additional values if the declaration contains #rest; otherwise, the function discards the additional values.