What is the benefit to use let-values instead of let?

Viewed 1252

The instance in my mind is this: what is better?

Example 1:

(define (foo x)
  ...
  (values a b c))

(let-values (((a b c) (foo  42)))
    ...)

Example 2:

(define (foo x)
  ...
  (list a b c))

(let ((f (foo 42)))
  (let ((x (first f)) (y (second f)) (z (third f)))
      ...))

My rough guess is that first way is the best because in the second because whenever there is call of first/second/third it has to iterate over the list. So my questione becomes: how does values work? Is it only syntactic sugar for a list or it uses something else? (e.g. an array)

If that depends on the implementation I let you know I'm working with chicken scheme.

3 Answers
Related