Returning multiple values in Scheme

In this thread in comp.lang.scheme the means to return multiple values are discussed. There are seemingly 3 solutions in R6RS:

(import (rnrs))

; let-values + values
(define (foo1)
  (values 1 2 3))

(let-values (((a b c) (foo1)))
  (display (list a b c))

; cps
(define (foo2 k)
  (k 1 2 3))

(foo2 (lambda (a b c)
        (display (list a b c))

; list
(define (foo3)
  (list 1 2 3))
(let ((result (foo3)))
  (display result)

Per Aziz and Aaron’s point; you should use the approach that communicates the most information to the reader.

Leave a Reply

Your email address will not be published. Required fields are marked *