[Prev][Next][Index][Thread]
Re: remove and <array>
in article Pine.GSO.3.96.1000921180124.14939H-100000@tardis.tardis.ed.ac.uk,
Hugh Greene at q@tardis.ed.ac.uk wrote on 2000.09.21 10:07 AM:
> 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.
Maybe something like the following would make it more obvious:
define generic remove-element(collection, key);
define generic remove-element!(collection, key);
define generic remove-elements(collection, key, count);
define generic remove-elements!(collection, key, count);
define generic add-element(collection, element, key)
define generic add-element!(collection, element, key)
define generic add-elements(collection, elements :: <collection>, key)
define generic add-elements!(collection, elements :: <collection>, key)
One should be able to easily implement these, but perhaps the issue is that
it isn't obvious in the DRM how to use replace-subsequence! for this (for
removal, anyway; perhaps it's more obvious how to use it to add elements).
Perhaps all it would take is an explicit mention about replacing with #().
Once you know about replace-subsequence! these generics may not really be
necessary; not for the Dylan library, anyway.
--
Chris Page
Mac OS Guy
Palm, Inc.
let mail-to = concatenate( "Chris Page <page", "@", "best.com>");
References: