HELP: <step-slice>
{ $values
- { "from" integer } { "to" integer } { "step" object } { "seq" sequence }
+ { "from/f" { $maybe integer } } { "to/f" { $maybe integer } } { "step" object } { "seq" sequence }
{ "step-slice" slice }
}
-{ $description "Outputs a new virtual sequence sharing storage with the subrange of elements in " { $snippet "seq" } " with indices starting from and including " { $snippet "from" } ", and up to but not including " { $snippet "to" } ", with step " { $snippet "step" } "." } ;
+{ $description "Outputs a new virtual sequence sharing storage with the subrange of elements in " { $snippet "seq" } " with indices starting from and including " { $snippet "from/f" } ", and up to but not including " { $snippet "to/f" } ", with step " { $snippet "step" } "."
+ $nl
+ "If " { $link f } "is given in place of " { $snippet "from/f" } ", it is taken as 0."
+ $nl
+ "If " { $link f } "is given in place of " { $snippet "to/f" } ", it is taken as the length of " { $snippet "seq" } "." }
+;
HELP: <zip-index>
{ $values
{ seq read-only }
{ step integer read-only } ;
-:: <step-slice> ( from to step seq -- step-slice )
+:: <step-slice> ( from/f to/f step seq -- step-slice )
step zero? [ "can't be zero" throw ] when
seq length :> len
step 0 > [
- from [ 0 ] unless*
- to [ len ] unless*
+ from/f [ 0 ] unless*
+ to/f [ len ] unless*
] [
- from [ len ] unless*
- to [ 0 ] unless*
+ from/f [ len ] unless*
+ to/f [ 0 ] unless*
] if
[ dup 0 < [ len + ] when 0 len clamp ] bi@
! FIXME: make this work with steps