Marc Nieper-Wißkirchen
This SRFI is currently in draft status. Here is an explanation of each status that a SRFI can hold. To provide input on this SRFI, please send email to srfi-195@nospamsrfi.schemers.org
. To subscribe to the list, follow these instructions. You can access previous messages via the mailing list archive.
This SRFI extends the specification of the boxes of SRFI 111 so that they are multiple-values aware. Whereas a SRFI 111 box is limited in that it can only box a single value, multiple values can be boxed with this SRFI.
There are currently no issues.
At its core, Scheme's evaluation semantics is multiple-value based. Continuations can accept an arbitrary number of values and expressions can yield an arbitrary number of values. This is contrast to the functional languages ML and Haskell.
Despite this fact, programming with multiple values is more
cumbersome than programming with single values. This is mostly
due to the fact that Scheme's application syntax does not deal
directly with operands returning multiple values so that the
programmer has to fall back on things
like call-with-values
. It is, however, also partly
due to the fact that a lot of Scheme's procedures have been
modelled on a language that does not have multiple values.
One example for this are the procedures exported by SRFI 111. In an ongoing attempt to make Scheme more uniform (and therefore also simpler) and so that multiple values feel less like a second-class citizen, this SRFI extends SRFI 111 so that it becomes multiple-values-aware in a natural way. The naturalness of the extension is a proof that it is the right extension.
The boxes of this SRFI can be used to reify the concept of multiple values into a first-class single value. This can be used in the implementation of SRFIs like SRFI 189.
Multiple-value-aware boxes as described in this SRFI form a
natural Scheme monad as much as the monads defined in SRFI 165
and SRFI 189 do. However, it is left to a future SRFI to
describe a monadic interface to boxes (the monadic pure would be
the box
procedure; the monadic join would
be unbox
when restricted to boxes whose values
consist of a single box).
In a Scheme system supporting both SRFI 111 and this SRFI, the bindings exported by both SRFIs have to be equivalent.
The following procedures implement the box type (which is disjoint
from all other Scheme types), and are exported by
the (srfi 111)
and (srfi 195)
libraries.
(box value …)
Constructor. Returns a newly allocated box initialized to
the value
s.
(box? object)
Predicate. Returns #t
if object
is a box, and #f
otherwise.
(unbox box)
Accessor. Returns the current values of box
.
(set-box! box value …)
Mutator. Changes box
to
hold value
s.
The behavior of boxes with the equivalence
predicates eq?
, eqv?
,
and equal?
is the same as if they were implemented
with records. That is, two boxes are both eq?
and eqv?
iff they are the product of the same call
to box and not otherwise, and while they must
be equal?
if they are eqv?
, the
converse is implementation-dependent.
A simple, portable R7RS-implementation of (srfi
195)
and a compatible (srfi 111)
is given in
the repository of this SRFI.
This SRFI is based on SRFI 111, written by John Cowan. In the specification section, I stole its language.
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.