For Development HEAD DRAFTSearch (procedure/syntax/module):

11.51 srfi.210 - Procedures and syntax for multiple values

Module: srfi.210

This module provides macros and procedures to blend multiple-value expressions naturally into the orinary single-value expressions.

Macro: with-values producer consumer

[SRFI-210]{srfi.210} A shorthand notation of (call-with-values (^[] producer) consumer).

Macro: case-receive producer clause …

[SRFI-210]{srfi.210} A shorthand notation of (with-values producer (case-lambda clause …)).

Macro: apply/mv operator operand … producer

[SRFI-210]{srfi.210} Similar to apply, but the multiple values yielded from the last argument (producer) is turned into the tail of the argument list; that is, (apply operator operand … (values->list producer)).

Macro: call/mv proc producer …

[SRFI-210]{srfi.210} Calls proc with the argument produced by the expression producer … and ’splicing’ their result(s) into a single argument list.

(call/mv list (values 1 2 3) (values 4 5 6))
  ⇒ (1 2 3 4 5 6)
Macro: list/mv element … producer
Macro: vector/mv element … producer
Macro: box/mv element … producer

[SRFI-210]{srfi.210} Returns a list, a vector, or a box, consisting of element … and the value(s) produced by producer.

Single-argument list/mv is the same as Gauche’s values->list (see Multiple values).

(list/mv 1 2 (values 3 4 5))   ⇒ (1 2 3 4 5)
(vector/mv 1 2 (values 3 4 5)) ⇒ #(1 2 3 4 5)
(box/mv 1 2 (values 3 4 5))    ⇒ #<mv-box[5] 1 2 3 4 5>
Macro: value/mv index element … producer

[SRFI-210]{srfi.210} Returns the same value as (list-ref (list/mv element … producer) index).

With no element …, it is the same as Gauche’s values-ref (see Multiple values) except the argument order.

Macro: coarity producer

[SRFI-210]{srfi.210} Evaluate producer, and returns the number of values it yielded.

Macro: bind/mv producer transducer …

[SRFI-210]{srfi.210} Evaluate producer, and passes its results to the first transducer as arguments. The values returned by the first transducer are passed to the next transducer as arguments, and so on. Returns the results of the last transducer. The call to the last transducer is tail-call.

If no transducers are given, it returns the results of producer.

Function: list-values lis
Function: vector-values vec
Function: box-values box

[SRFI-210]{srfi.210} Turn the content of lis, vec or box into multiple values.

Note that box-values is the same as unbox, but provided here for the naming consistency (see Boxes).

Function: value index obj …

[SRFI-210]{srfi.210} Returns the index-th value of obj ….

Function: identity obj …

[SRFI-210]{srfi.210} Synonym of values. Note that this is different from Gauche’s built-in identity, which takes exactly one argument (see Combinators).

Function: compose-left transducer …

[SRFI-210]{srfi.210} Each transducer must be a procedure. Returns a procedure that applies the first transducer to its arguments, then applies the next transducer to the result(s) of the first one, and so on. Returns the result(s) returned from the last transducer. If no tranducers are given, returned procedure is the same as values.

This can be written using Gauche’s built-in compose as follows (see Combinators):

(define (compose-left . procs) (apply compose (reverse procs)))
Function: compose-right transducer …

[SRFI-210]{srfi.210} Each transducer must be a procedure. Returns a procedure that applies the last transducer to its arguments, then applies the previous transducer to the result(s) of the last one, and so on. Returns the result(s) returned from the first transducer. If no tranducers are given, returned procedure is the same as values.

This is the same as Gauche’s built-in compose (see Combinators).

Function: map-values proc

[SRFI-210]{srfi.210} Returns a procedure that takes any number of arguments, applys proc on each argument, and returns the results as multiple values. The behavior is undefined if proc doesn’t return a single value.

((map-values (cut + <> 1)) 1 2 3)
  ⇒ 2, 3, 4
Function: bind/list lis transducer …
Function: bind/box box transducer …
Function: bind obj transducer …

[SRFI-210]{srfi.210} These are bind operation in Monads. The first argument is the source of data; they’re first expanded into values (for bind/list, each element of lis is taken; for bind/box, it is unboxed, and for bind, obj is the singleton value). Those values are passed as arguments to the first transducer, and its result(s) are passed as argumenst to the second transducer and so on. The value(s) returned by the last transducer becomes the result(s) of those procedures. These can be written using compose-left and procedure application:

(bind/list lis proc ...)
  ≡ (apply (compose-left proc ...) lis)
(bind/box box proc ...)
  ≡ (apply/mv (compose-left proc ...) (unbox box))
(bind obj proc ...)
  ≡ ((compose-left proc ...) obj)


For Development HEAD DRAFTSearch (procedure/syntax/module):
DRAFT