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

Re: Can array-ref return (values ...) ?

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



<David Rush topic="(values ...)">
Ok, it's a procedure that accesses the current continuation
then. It is a very odd procedure in since it can only be called in
tail position. It *still* does not construct a data object, so it
cannot be the "contents" of an array element. IOW,

        (vector-set! v n (values 4 3 2))

is completely meaningless. Therefore the contents of a single element
cannot be (values a b).
</ David Rush>

When vectors were introduced to Scheme, there were no (values ...) and
(call-with-values ...).  Now there are.  There were no macros.  Now there
are.  So now we can use these procedures and macros to build new data
abstractions if we want.

So we could have (array-ref a i) and (array-set! a i v)
be special forms (macros) that expand to

(call-with-values
    (lambda () i)
  (lambda indices
    (array-body-ref a indices)))

and

(call-with-values
    (lambda () i)
  (lambda indices
    (call-with-values
	(lambda () v)
      (lambda vals
	(array-body-set! a indices vals)))))

All of a sudden, (array-ref a (values 1 2 3)) and
(array-set! a (values 1 2 3) (values #t #f)) make
sense.  And it also makes sense that array-ref can return
multiple values.  You, as the programmer, just have to be sure
that if array-ref returns zero or more than one value that
it's in a continuation built with (call-with-values ...).

So I don't believe these vehement denials that this is possible.

I can believe that someone (or everyone but I) might say "I
don't want to do this".

Brad