On Mon, May 29, 2023 at 7:47 AM John Cowan <[email protected]> wrote:

> On Sat, May 27, 2023 at 4:31 AM Alex Shinn <[email protected]> wrote:
>
>
>> The expensive path is array-copy of an array-map or other generalized
>> array.
>>
>
> True, but because array-map is lazy there is never any guarantee that
> getting an element of an array constructed by array-map returns the same
> value every time (e.g. it could return a random number), and so *actual*
> safety, as opposed to formal call/cc-safety, is never guaranteed whether
> you make an intermediate list or not.
>

I'm not sure I understand this analogy.  What do you mean by safety here?
A lazy random array will return different values for every element access
to the original array.  A copy would produce one snapshot in time of this
ever changing array.  This seems to be WAI.


>   A "sufficiently smart compiler" could transform the idiom (array-copy
> (array-map ...)) to use array-copy! instead.
>

Indeed, but in practice none of the implementations providing SRFI 231 do
this now, and such optimizations are fragile.  You risk the compiler not
detecting the fast path in some cases.  If it were a small penalty we could
optimistically look to the future, but the wasted space here is much too
large to ignore.

-- 
Alex

Reply via email to