]> gitweb.factorcode.org Git - factor.git/commitdiff
change clump when the group size is greater than the sequence length
authorJon Harper <jon.harper87@gmail.com>
Sun, 28 Oct 2012 13:34:55 +0000 (14:34 +0100)
committerDoug Coleman <doug.coleman@gmail.com>
Sun, 28 Oct 2012 20:34:08 +0000 (13:34 -0700)
basis/grouping/grouping-docs.factor
basis/grouping/grouping-tests.factor
basis/grouping/grouping.factor

index 2b183c3364893a5900586852c5c8090d2c0284c0..dc81e3d3d8cb23ed69b89706042a565d29645ec3 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." }
-{ $errors "Throws an error if " { $snippet "n" } " is larger than the length of the sequence." }
+{ $notes "If the sequence length is smaller than " { $snippet "n" } ", the result will be an array with one element: the original sequence " { $snippet "seq" } "." }
 { $examples
     { $example "USING: grouping prettyprint ;" "{ 3 1 3 3 7 } 2 clump ." "{ { 3 1 } { 1 3 } { 3 3 } { 3 7 } }" }
 } ;
index 9340b322e2d9e2da91a40a4e9c6300e3d29417e2..104f9a731111031b59d62244b34414865fbf6cf3 100644 (file)
@@ -12,8 +12,8 @@ IN: grouping.tests
     >array
 ] unit-test
 
-[ 0 ] [ { } 2 <clumps> length ] unit-test
-[ 0 ] [ { 1 } 2 <clumps> length ] unit-test
+[ 1 ] [ { } 2 <clumps> length ] unit-test
+[ 1 ] [ { 1 } 2 <clumps> length ] unit-test
 [ 1 ] [ { 1 2 } 2 <clumps> length ] unit-test
 [ 2 ] [ { 1 2 3 } 2 <clumps> length ] unit-test
 
index 83d48a14ad5e887dfbcbe2d8278a5673b86b4f22..ff13d1ab4b2315a311f4aff255b84fbaff960a52 100644 (file)
@@ -44,13 +44,13 @@ MIXIN: abstract-clumps
 INSTANCE: abstract-clumps sequence
 
 M: abstract-clumps length
-    [ seq>> length 1 + ] [ n>> ] bi [-] ; inline
+    [ seq>> length 1 + ] [ n>> ] bi - 1 max ; inline
 
 M: abstract-clumps set-length
     [ n>> + 1 - ] [ seq>> ] bi set-length ; inline
 
 M: abstract-clumps group@
-    [ n>> over + ] [ seq>> ] bi ; inline
+    [ [ n>> over + ] [ seq>> length ] bi min ] [ seq>> ] bi ; inline
 
 TUPLE: chunking-seq { seq read-only } { n read-only } ;