[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

10.6 srfi-11 - Let-values

Module: srfi-11
Defines two macros, let-values and let*-values. They are convenient to use with multiple values ([SRFI-11]).

Macro: let-values ((vars expr) ...) body ...
[SRFI-11] vars are a list of variables. expr is evaluated, and its first return value is bound to the first variable in vars, its second return value to the second variable, and so on, then body is evaluated. The scope of exprs are the outside of let-values form, like let.

 
(let-values (((a b) (values 1 2))
             ((c d) (values 3 4)))
  (list a b c d)) => (1 2 3 4)

(let ((a 1) (b 2) (c 3) (d 4))
  (let-values (((a b) (values c d))
               ((c d) (values a b)))
    (list a b c d))) => (3 4 1 2)

vars can be a dotted list or a single symbol, like the lambda parameters.

 
(let-values (((x . y) (values 1 2 3 4)))
  y) => (2 3 4)

(let-values ((x (values 1 2 3 4)))
  x) => (1 2 3 4)

If the number of values returned by expr doesn't match what vars expects, an error is signalled.

Macro: let*-values ((vars expr) ...) body ...
[SRFI-11] Same as let-values, but each expr's scope includes the preceding vars.

 
(let ((a 1) (b 2) (c 3) (d 4))
  (let*-values (((a b) (values c d))
                ((c d) (values a b)))
    (list a b c d))) => (3 4 3 4)



This document was generated by Ken Dickey on November, 28 2002 using texi2html