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?
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-values
inside macro:There are also
define-values
andlet-values
, if you know number of returned values.Source: R7RS report