]> gitweb.factorcode.org Git - factor.git/commitdiff
clump: fix empty sequence input. rephrase docs a bit
authorJon Harper <jon.harper87@gmail.com>
Sun, 28 Oct 2012 14:28:05 +0000 (15:28 +0100)
committerDoug Coleman <doug.coleman@gmail.com>
Sun, 28 Oct 2012 20:34:18 +0000 (13:34 -0700)
basis/grouping/grouping-docs.factor
basis/grouping/grouping.factor

index dc81e3d3d8cb23ed69b89706042a565d29645ec3..83f9173f1fc128e25badf40c4fcc97374389629f 100644 (file)
@@ -117,7 +117,7 @@ $nl
 HELP: clump
 { $values { "seq" "a sequence" } { "n" "a non-negative integer" } { "array" "a sequence of sequences" } }
 { $description "Splits the sequence into overlapping clumps of " { $snippet "n" } " elements and collects the clumps into a new array." }
-{ $notes "If the sequence length is smaller than " { $snippet "n" } ", the result will be an array with one element: the original sequence " { $snippet "seq" } "." }
+{ $notes "For an empty sequence, the result is an empty sequence. For a non empty sequence with a length smaller than " { $snippet "n" } ", the result will be a sequence with one element: the input sequence " { $snippet "seq" } "." }
 { $examples
     { $example "USING: grouping prettyprint ;" "{ 3 1 3 3 7 } 2 clump ." "{ { 3 1 } { 1 3 } { 3 3 } { 3 7 } }" }
 } ;
index ff13d1ab4b2315a311f4aff255b84fbaff960a52..b2f850cf4992e5eed292c777b542933665cac9a2 100644 (file)
@@ -44,7 +44,9 @@ MIXIN: abstract-clumps
 INSTANCE: abstract-clumps sequence
 
 M: abstract-clumps length
-    [ seq>> length 1 + ] [ n>> ] bi - 1 max ; inline
+    dup seq>> length [ drop 0 ] [
+        swap [ 1 + ] [ n>> ] bi* - 1 max
+    ] if-zero ; inline
 
 M: abstract-clumps set-length
     [ n>> + 1 - ] [ seq>> ] bi set-length ; inline