Possible errata for array-assign!, re: continuations and array setters Bradley Lucier 03 Jan 2023 21:02 UTC

There was some discussion about array-stack, array-block, array-append,
array-block, and array-copy being implemented in a "call/cc-safe" way.
And a statement was added that for the "bang" versions of these routines
it is an error to invoke the continuation of an array's getter more than
once.

But we did not consider how a generalized array's setter interacts with
call/cc.

This only matters when an array's setter is passed (explicitly or
implicitly) to a higher-order procedure.

And the only place that I can see this happening in this SRFI is in

(array-assign! destination source)

The implementation does the following:

For each multi-index in the common domain of destination and source, in
lexicographical order, evaluate the source's getter at that multi-index
to get a value, and then evaluate the destination's setter with that
value at that multi-index.

So it alternates evaluating the source's getter and the destination's
setter:

https://github.com/scheme-requests-for-implementation/srfi-231/blob/59fdf7eb518c16b446a8a3b76ef8185b4bd57082/generic-arrays.scm#L2784

One could imaging instead copying the source in a call/cc-safe way to a
specialized array and then calling the destination's setter for each
value and multi-index in the newly allocated specialized array.

I don't want to do this.  This would require a lot more intermediate
copying.  (See the Gaussian Elimination example.)

After thinking about it for two days, I came up with two possible
changes.  I'm open to other suggestions.

================================================

1.  Add the sentence

It is an error if the continuation of each call to source's getter or
destination's setter is invoked more than once.

To the specification of array-assign!

2.  Add the sentence

It is an error if the continuation of each call to source's getter or
destination's setter is invoked more than once.

to the specification of array-assign! and add the sentence

It is an error if the continuation of each call to array's getter is
invoked more than once.

to the specifications of array-copy!, array-stack!, array-decurry!,
array-append!, and array-block!.

================================================
I took this sentence from the current list item "This SRFI and
call-with-current-continuation".
================================================

Strictly speaking, the list item "This SRFI and
call-with-current-continuation" already covers the situation for
array-copy!, array-stack!, array-decurry!, array-append!, and
array-block!, but it would be clearer if the sentence was attached to
the specification of each procedure.  (I think John already may have
already suggested this, but I didn't do it.)

Brad