Previous chapter: #14: Union Allows Duplicates (Clarification)

Dylan Design Notes: #15: Replace-Subsequence! Different Sizes (Change)

## Dylan Design Notes

# #15: Replace-Subsequence! Different Sizes (Change)

Version 1, March 1993

This design note extends the definition of replace-subsequence! to
allow the old and new subsequences to have different sizes. This
change greatly increases the utility of replace-subsequence!,
enabling it to be used for replace, insert and delete operations over
any sequence.

Replace the definition of replace-subsequence! on page 108 of the Dylan book with the following:

replace-subsequence! sequence insert-sequence
#key start end => result-sequence [Generic Function]

This function returns a sequence with the same elements as sequence,
except that elements of the indicated subsequence are replaced by all
the elements of insert-sequence. The subsequence to be overridden
begins at index start and ends at index end. If start is not
supplied, it defaults to 0. If end is not supplied, it defaults to
(size sequence ). result-sequence may or may not share structure
with sequence , it may or may not be id? to sequence , and sequence
may or may not be modified by the operation. result-sequence will
not share structure with insert-sequence.
? (define abcde (list 'a 'b 'c 'd 'e)
;unspecified
? (set! abcde (replace-subsequence! abcde '(x y z) end: 1))
(x y z b c d e)
? (set! abcde (replace-subsequence! abcde '(x y z) start: 4))
(x y z b x y z)
? (set! abcde (replace-subsequence! abcde '(a b c) start: 2 end: 4))
(x y a b c x y z)
? (set! abcde (replace-subsequence! abcde' () start: 2 end: 7))
(x y z)
? (set! abcde (replace-subsequence! abcde '(a b c)))
(a b c)
? (set! abcde (replace-subsequence! abcde '(x y z) start: 3))
(a b c x y z)
? (replace-subsequence! abcde "")
()

Next chapter: #16: List Issues (Change)