Given a Scheme function returning multiple values, for example:
(exact-integer-sqrt 5) ⇒ 2 1
How can I use only the first returned value, ignoring the other ones?
Given a Scheme function returning multiple values, for example:
(exact-integer-sqrt 5) ⇒ 2 1
How can I use only the first returned value, ignoring the other ones?
On
Simply use let-values:
(let-values (((root rem) (exact-integer-sqrt 5)))
root)
The above will extract both results in separate variables, and you can choose which one you need.
You can use
call-with-valuesinside macro:There are also
define-valuesandlet-values, if you know number of returned values.Source: R7RS report