shorten ( n seq -- )


Vocabulary
sequences

Inputs and outputs
nan integer
seqa sequence


Word description
Shortens a Resizable sequence implementation sequence to be n elements long.

Examples
USING: sequences prettyprint kernel ; V{ 1 2 3 4 5 } 3 over shorten .
V{ 1 2 3 }


Definition
IN: sequences

GENERIC: shorten ( n seq -- )


Methods
USING: accessors growable kernel math sequences
sequences.private ;

M: growable shorten
bounds-check-head 2dup length <
[ 2dup contract 2dup length<< ] when 2drop ; inline


USING: kernel math sequences ;

M: sequence shorten
2dup length < [ set-length ] [ 2drop ] if ; inline