Producing and Consuming Multiple Values

Use values to return a value packet and call-with-values to connect that packet to a consumer with matching arity.

At a glance

LISPEX
(call-with-values (lambda () (values 3 4)) (lambda (a b) (+ (* a a) (* b b))))

Result

OUTPUT
25

Working method

  • Place the producer in the dedicated producer context, not in a call operand, test, binding initializer, or assignment RHS.
  • The consumer receives each produced value as one argument and is arity-checked normally.
  • Use (values) deliberately for zero values in discard-capable control paths.

Boundaries

  • Do not encode semantic multiple values as an ordinary list when the caller expects value arity.