4 Program Control
Multiple values are generated by the function
values. They are received by the bindings of
let declarations and
define constant and
define variable definitions.
Many statements will return multiple values if the last expression they execute returns multiple values. Similarly, a function will return all the values of the last subexpression it executes.
define method return-three-values (a, b, c)
values(a, b, c)
end method return-three-values;
let (foo, bar, baz) = return-three-values (1, 2, 3);
list (foo, bar, baz)
=> #(1, 2, 3)
Each expression in the argument list of a function call supplies only one argument to the function call. That argument is the first value returned by the expression. Additional values returned by the expressions are ignored.
list (return-three-values(1, 2, 3), return-three-values(1, 2, 3), return-three-values(1, 2, 3))Multiple values can be used to perform parallel binding:
Þ #(1, 1, 1)
let x = 10;
let y = 20;
let (x, y) = values (y, x);
list (x, y);
The following rules apply when matching up an expression which returns multiple values with a binding declaration or definition that receives multiple values.
#f. (If a binding is typed,
#fmust be an instance of its type or an error is signaled.)
begin let (one #rest nums) = return-three-values(1, 2, 3); nums; end
Þ #(2, 3)
Generated with Harlequin WebMaker