by Marc Nieper-Wißkirchen
This SRFI is currently in final status. Here is an explanation of each status that a SRFI can hold. To provide input on this SRFI, please send email to srfi-244@nospamsrfi.schemers.org
. To subscribe to the list, follow these instructions. You can access previous messages via the mailing list archive.
A define-values
form is a definition that binds
multiple variables from a single expression returning multiple
values.
This SRFI makes the define-values
definition,
which was standardized in R7RS, available to
R6RS systems.
It is preferable for define-values
to be
implemented in the Scheme system's core so that modifications of
an algorithm like the one described
in Fixing Letrec
(reloaded) can be employed to
implement define-values
definitions as effectively
as other internal variable definitions.
This specification describes the (srfi :244)
and (srfi :244 define-values)
libraries.
The define-values
form described in this specification is
a 〈definition〉
and may appear anywhere
other definitions may appear.
(define-values 〈formals〉 〈expression〉)
Syntax: Any variable must not appear more than once in
the set of 〈formals〉
.
Semantics: The variables occurring in
the 〈formals〉
are bound to fresh
locations containing the values returned by
the 〈expression〉
, where
the 〈formals〉
are matched to the return
values in the same way that the 〈formals〉
in a lambda
expression are matched to the arguments
in a procedure call. The effect of the 〈formals〉
not matching is undefined.
The continuation of 〈expression〉
should
not be invoked more than once.
(define-values (x y) (values 1 2)) (+ x y) ⟹ 3 (define-values (a . b) (values 1 2)) (cons a b) ⟹ (1 2)
Sample implementation as a portable R6RS library
The form described in this SRFI has been well-known for a long time.
I would like to thank Jim Rees for pointing out to me that the
original sample implementation violated the R6RS
requirement that it is a syntax violation to
use set!
with exported variables.
Abdulaziz Ghuloum and R. Kent Dybvig. Fixing letrec (reloaded). In Proceedings of the 2009 Workshop on Scheme and Functional Programming, 57–65, 2009.
© 2022 Marc Nieper-Wißkirchen.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.