set-nth ( elt n seq -- )
Factor handbook » The language » Collections » Sequence operations » Sequence protocol

Prev:?nth ( n seq -- elt/f )
Next:set-nth-unsafe ( elt n seq -- )


Vocabulary
sequences

Inputs
eltan object
na non-negative integer
seqa mutable sequence


Outputs
None

Generic word contract
Sets the nth element of the sequence. Storing beyond the end of a resizable sequence such as a vector or string buffer grows the sequence.

Errors
Throws an error if the index is negative, or if the sequence is not resizable and the index is greater than or equal to the length of the sequence.

Throws an error if the sequence cannot hold elements of the given type.

Side effects
Modifies seq

Examples
USING: kernel prettyprint sequences ; 99 0 { 1 1 1 } [ set-nth ] keep .
{ 99 1 1 }

USING: kernel prettyprint sequences ; 99 8 V{ 1 1 1 } [ set-nth ] keep .
V{ 1 1 1 0 0 0 0 0 99 }


Definition

GENERIC: set-nth ( elt n seq -- )


Methods