( Multiple Values

Info Catalog ( Continuations ( Control Mechanisms ( Exceptions
 26.6 Returning and Accepting Multiple Values
 Scheme allows a procedure to return more than one value to its caller.
 This is quite different to other languages which only allow
 single-value returns.  Returning multiple values is different from
 returning a list (or pair or vector) of values to the caller, because
 conceptually not _one_ compound object is returned, but several
 distinct values.
    The primitive procedures for handling multiple values are `values'
 and `call-with-values'.  `values' is used for returning multiple values
 from a procedure.  This is done by placing a call to `values' with zero
 or more arguments in tail position in a procedure body.
 `call-with-values' combines a procedure returning multiple values with
 a procedure which accepts these values as parameters.
  -- Scheme Procedure: values . args
  -- C Function: scm_values (args)
      Delivers all of its arguments to its continuation.  Except for
      continuations created by the `call-with-values' procedure, all
      continuations take exactly one value.  The effect of passing no
      value or more than one value to continuations that were not
      created by `call-with-values' is unspecified.
  -- Scheme Procedure: call-with-values producer consumer
      Calls its PRODUCER argument with no values and a continuation
      that, when passed some values, calls the CONSUMER procedure with
      those values as arguments.  The continuation for the call to
      CONSUMER is the continuation of the call to `call-with-values'.
           (call-with-values (lambda () (values 4 5))
                             (lambda (a b) b))
                                                        ==>  5
           (call-with-values * -)                             ==>  -1
    In addition to the fundamental procedures described above, Guile has
 a module which exports a syntax called `receive', which is much more
 convenient.  If you want to use it in your programs, you have to load
 the module `(ice-9 receive)' with the statement
      (use-modules (ice-9 receive))
  -- library syntax: receive formals expr body ...
      Evaluate the expression EXPR, and bind the result values (zero or
      more) to the formal arguments in the formal argument list FORMALS.
      FORMALS must have the same syntax like the formal argument list
      used in `lambda' ( Lambda).  After binding the variables,
      the expressions in BODY ... are evaluated in order.
Info Catalog ( Continuations ( Control Mechanisms ( Exceptions
automatically generated byinfo2html