[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Difference between values->list and list

This page is part of the web mail archives of SRFI 71 from before July 7th, 2015. The new archives for SRFI 71 contain all messages, not just those from before July 7th, 2015.

Hello Christian,

No VALUES->LIST and LIST do different things.

To understand the difference, let's have a look at an implementation:

(define list
   (lambda xs xs))

(define-syntax values->list
  (syntax-rules ()
    ((values->list x)
     (call-with-values (lambda () x) list))))

As you can see, LIST is a procedure returning the list of its arguments.

VALUES-LIST on the other hand is a macro evaluating its single
argument (called x above) by calling the produce procedure (lambda () x).
This evaluation may result in several values, on which call-with-values
calls the consumer procedure LIST.

The important thing is that "producing several values" is not the
same as "returning a list with several elements". You can imagine
the process transfering several values from a produce to a consumer
as follows: (lambda () x) executes machine instructions that leave
several results in a couple of CPU registers used for results. Call-with-values
then moves all the data from the result registers into the argument
registers for the next procedure and calls the consumer procedure.
In practice, this may not be the way it is happening because the
Scheme system can implement the transfer of values in many
different ways, but I hope you get the picture.