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

Re: remove and <array>



On Thu, 21 Sep 2000, P T Withington wrote:
> Bruce Hoult bruce@hoult.org on  2000-09-20 19:45 wrote:
> > In article <B5EEB991.D63F%ptw@curl.com>, P T Withington <ptw@curl.com>
> > wrote:
> > 
> >> Am I misreading the reference manual, or are remove and remove-key really
> >> not available on <vector>?
> > 
> > What would they do?  They're available for <stretchy-vector>.
> 
> Keith got my drift.  remove could (and does) return a copy of the vector
> with the argument element removed.  I was thinking that remove-key would
> remove the element at a particular index, but that is not consistent with
> the contract of remove-key (because the key would still exist, except for
> the case of the very last element).
> 
> Perhaps what I want is the ability to insert and delete at a particular
> index (key) in (implicit-key-collection) sequences.  ...

(Just to be clear, "implicit-key-collections" *are* <sequence>s, by
definition.)

> ... I don't see such
> functionality specified in the DRM, but perhaps it is in a library?

This has confused me more than once.  I eventually worked out that what
you need to use, somewhat oddly, is replace-subsequence!.  This then
should automagically work for stretchy or non-stretchy sequences.  (I say
should because there aren't actually any methods defined in the DRM; I'd
want one on <sequence> and one on <stretchy-sequence> at least.) 

// To remove an element at index
seq := replace-subsequence!(seq, #(), start: index, end: index);

// To insert some elements at index
seq := replace-subsequence!(
  seq, #["some", "elements"], start: index, end: index
);

Cute, once you work it out, but non-obvious.

HTH,
Hugh



Follow-Ups: References: