<step-slice> ( from/f to/f step seq -- step-slice )


Vocabulary
sequences.extras

Inputs
from/fan integer or f
to/fan integer or f
stepan object
seqa sequence


Outputs
step-slicea slice


Word description
Outputs a new virtual sequence sharing storage with the subrange of elements in seq with indices starting from and including from/f, and up to but not including to/f, with step step.

If fis given in place of from/f, it is taken as 0.

If fis given in place of to/f, it is taken as the length of seq.

Definition


:: <step-slice> ( from/f to/f step seq -- step-slice )
step zero? [ "can't be zero" throw ] when
seq length :> len step 0 >
[ from/f [ 0 ] unless* to/f [ len ] unless* ]
[ from/f [ len ] unless* to/f [ 0 ] unless* ] if
[ dup 0 < [ len + ] when 0 len clamp ] bi@ seq dup slice?
[ collapse-slice ] when step step-slice boa ;