Next: , Previous: Pre-Scheme record types, Up: More Pre-Scheme packages


9.4.3 Multiple return values

Pre-Scheme support multiple return values, like in Scheme. The only difference is that one cannot operate on multiple return values as lists, since Pre-Scheme does not have lists. Multiple return values are implemented in C as returning in C the first value and passing pointers to the remaining values, which the function returning multiple values assigns. The prescheme structure exports the two multiple return value primitives, call-with-values and values, but the ps-receive structure exports this macro for more conveniently binding multiple return values.

— syntax: receive formals producer body

Binds the lambda parameter list formals to the multiple values that producer returns, and evaluates body with the new variables bound.

          (receive formals
                   producer
            body)
              ==
          (call-with-values
              (lambda () producer)
            (lambda formals
              body))