Multiple Return Values in Scheme
Scheme has built-in support for multiple return values. This feature is used often in idiomatic Scheme, for example to return both result and error values from a function.
The (values 3 7)
in the vals
function shows that the function returns 2 values.
In the main
function, we use the 2 different return values from the call with multiple value binding using let-values
.
If you only want a subset of the returned values, use underscore _
as a placeholder.
To run the program, you would typically save it to a file (e.g., multiple-return-values.scm
) and run it with your Scheme interpreter. For example, if you’re using Guile:
Returning multiple values is a powerful feature in Scheme that allows for more expressive and efficient code in many situations.