Skip to content

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))
  (newline))
 
; cps
(define (foo2 k)
  (k 1 2 3))
 
(foo2 (lambda (a b c) 
        (display (list a b c))
        (newline)))
 
; list
(define (foo3)
  (list 1 2 3))
(let ((result (foo3)))
  (display result)
  (newline))

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

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*