]> gitweb.factorcode.org Git - factor.git/commitdiff
sequences.extras: correct stack effect for <step-slice> and explain the effect
authorrazetime <raghuallthetime@hotmail.com>
Wed, 21 Dec 2022 03:04:43 +0000 (08:34 +0530)
committerrazetime <raghuallthetime@hotmail.com>
Wed, 21 Dec 2022 03:04:43 +0000 (08:34 +0530)
extra/sequences/extras/extras-docs.factor
extra/sequences/extras/extras.factor

index 97ac34ed813416c9b25f4597d9c1841a130cc8ce..10b393a1b26d91f32c236b7f28d8c9660b007b1b 100644 (file)
@@ -499,10 +499,15 @@ HELP: 3nested-map
 
 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
index 027a3af19969716904c232efaf834c26190bfbdf..149f7814e168723c3c6bae82274293e26a06d9fb 100644 (file)
@@ -748,15 +748,15 @@ TUPLE: step-slice
     { 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