Multiple Values

Multiple values aren't a data structure: they're a protocol between producer and consumer that avoids allocating lists.

(values 1 2 3)                               ; returns three values
(call-with-values (lambda () (values 1 2)) +)   ; 3
(call-with-values (lambda () (floor/ 17 5)) list)   ; (3 2)

(define (min-max lst)
  (values (apply min lst) (apply max lst)))

(let-values (((lo hi) (min-max '(3 1 4 1 5))))
  (list lo hi))                              ; (1 5)

(let*-values (((a b) (values 1 2))
              ((c) (values (+ a b))))
  c)                                         ; 3

(define-values (q r) (floor/ 17 5))          ; R7RS top-level/internal definition
(list q r)                                   ; (3 2)

(let-values (((first . rest) (values 1 2 3))) rest)   ; (2 3)
;; SRFI-8: (receive (a b) (values 1 2) (+ a b)) → 3