9.1 Multiple Values

► |  | The Racket Reference

1 | Language Model
2 | Syntactic Forms
3 | Datatypes
4 | Structures
5 | Classes and Objects
6 | Units
7 | Contracts
8 | Pattern Matching
9 | Control Flow
10 | Concurrency and Parallelism
11 | Macros
12 | Input and Output
13 | Reflection and Security
14 | Operating System
15 | Memory Management
16 | Unsafe Operations
17 | Running Racket
| Bibliography
| Index

▼ | 9 | Control Flow

9.1 | Multiple Values
9.2 | Exceptions
9.3 | Delayed Evaluation
9.4 | Continuations
9.5 | Continuation Marks
9.6 | Breaks
9.7 | Exiting

On this page:

values
call-with-values

top ← prev up next →

#### 9.1`` Multiple Values

See Multiple Return Values for general information about multiple result values. In addition to call-with-values (described in this section), the let-values, let*-values, letrec-values, and define-values forms (among others) create continuations that receive multiple values.

> procedure (values v ...) → any
> v : any/c

Returns the given vs. That is, values returns as provided arguments.

Examples:
> > (values 1)
> 1
> > (values 1 2 3)
> 1
> 2
> 3
> > (values)

> procedure (call-with-values generator receiver) → any
> generator : (-> any)
> receiver : procedure?

Calls generator, and passes the values that generator produces as arguments to receiver. Thus, call-with-values creates a continuation that accepts any number of values that receiver can accept. The receiver procedure is called in tail position with respect to the call-with-values call.

Examples:
> > (call-with-values (lambda () (values 1 2)) +)
> 3
> > (call-with-values (lambda () 1) (lambda (x y) (+ x y)))
> #<procedure>: arity mismatch;
> the expected number of arguments does not match the given
> number
> expected: 2
> given: 1
> arguments...:
> 1

top ← prev up next →