Re: [Scheme-reports] vector-insert John Cowan (19 Aug 2014 17:26 UTC)
Re: [Scheme-reports] vector-insert Pierpaolo Bernardi (19 Aug 2014 18:30 UTC)
Re: [Scheme-reports] vector-insert John Cowan (19 Aug 2014 19:01 UTC)
Re: [Scheme-reports] vector-insert Pierpaolo Bernardi (20 Aug 2014 00:38 UTC)

Re: [Scheme-reports] vector-insert Pierpaolo Bernardi 19 Aug 2014 18:26 UTC

On Tue, Aug 19, 2014 at 7:22 PM, John Cowan <cowan@mercury.ccil.org> wrote:
> Alan Watson scripsit:
>
>> If I understand correctly, when the first element is assigned to the
>> new vector, surely the implementation would have to clear the bit and
>> initialise the other elements?
>
> That would be the safe thing, yes, but R7RS does not explicitly require either
> safety or unsafety.  I would not want to standardize anything that can't be
> made safe, but an unsafe implementation that can only be used in limited
> ways (viz. you are not allowed to gc the source vector until the destination
> vector is fully initialized) isn't necessarily unusable.

I don't think this is an operation useful enough to spend brain cycles
on possible ways to optimize it. But, if we really need this, here's
my proposal:

(make-vector-from-pieces dim default init...)

where each of the inits specifies a range to be filled in the new
vector, and an existing vector with a starting point, to be copied in
that range.  Ranges not included in any /init/ will be initialized
with /default/, as in make-vector.

This function can be implemented trivially in any Scheme, and an
implementor can supply a version for his implementation which avoids
double assignments in the newly  created vector, and is also safe.

P.

_______________________________________________
Scheme-reports mailing list
Scheme-reports@scheme-reports.org
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports