exchange-subseq ( len pos1 pos2 seq -- )


Vocabulary
sequences.extras

Inputs
lena non-negative integer
pos1a non-negative integer
pos2a non-negative integer
seqa mutable sequence


Outputs
None

Word description
Exchanges the contents of subsequences [pos1, pos1+len) and [pos2, pos2+len) in seq. Overlapping ranges are allowed. If either of the ranges exceeds the seq length, throws an error before any modifications take place. If len = 1, the behavior is equivalent to exchange.

Examples
Non-overlapping ranges:
USING: kernel sequences.extras prettyprint ; 2 0 3 "01_34_" [ exchange-subseq ] keep .
"34_01_"

Overlapping ranges:
USING: kernel sequences.extras prettyprint ; 3 0 2 "abcdef" [ exchange-subseq ] keep .
"cdebaf"


Side effects
Modifies seq

See also
exchange

Definition