3.7 Multiple Values
When values is immediately called using the default #%call operator, then static information for the call expression propagates static information for the expr arguments (using statinfo_meta.values_key).
The values operator can also be used to form a repetition.
> values("apple")
"apple"
> values("apple", 1)
"apple"
1
> block:
[x, y]
[1, 2]
Plain parentheses as a binding (as implemented by the #%parens form) work as an alias for values in the places that recognize values.
> x+y
3
values(1, 2)
> x+y
3
reducer | ||||||||||||
| ||||||||||||
| ||||||||||||
reducer | ||||||||||||
| ||||||||||||
| ||||||||||||
| ||||||||||||
| ||||||||||||
|
The fold reducer form is an alias for values.
sum + i
55
55
3628800
function | ||
|
Use call_with_values to dispatch on the number of values that are produced by an expression. The match form cannot make that distinction, because it always expects a single result value from its initial subexpression.
> call_with_values(fun (): get_fruit(0), show)
nothing
> call_with_values(fun (): get_fruit(1), show)
apple
> call_with_values(fun (): get_fruit(2), show)
apple and banana
> call_with_values(fun (): get_fruit(3), show)
apple and 3 bananas