change clump when the group size is greater than the sequence length

db4
Jon Harper 2012-10-28 14:34:55 +01:00 committed by Doug Coleman
parent 40ca3fc7f3
commit 2fc1442771
3 changed files with 5 additions and 5 deletions

View File

@ -117,7 +117,7 @@ $nl
HELP: clump HELP: clump
{ $values { "seq" "a sequence" } { "n" "a non-negative integer" } { "array" "a sequence of sequences" } } { $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." } { $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 { $examples
{ $example "USING: grouping prettyprint ;" "{ 3 1 3 3 7 } 2 clump ." "{ { 3 1 } { 1 3 } { 3 3 } { 3 7 } }" } { $example "USING: grouping prettyprint ;" "{ 3 1 3 3 7 } 2 clump ." "{ { 3 1 } { 1 3 } { 3 3 } { 3 7 } }" }
} ; } ;

View File

@ -12,8 +12,8 @@ IN: grouping.tests
>array >array
] unit-test ] unit-test
[ 0 ] [ { } 2 <clumps> length ] unit-test [ 1 ] [ { } 2 <clumps> length ] unit-test
[ 0 ] [ { 1 } 2 <clumps> length ] unit-test [ 1 ] [ { 1 } 2 <clumps> length ] unit-test
[ 1 ] [ { 1 2 } 2 <clumps> length ] unit-test [ 1 ] [ { 1 2 } 2 <clumps> length ] unit-test
[ 2 ] [ { 1 2 3 } 2 <clumps> length ] unit-test [ 2 ] [ { 1 2 3 } 2 <clumps> length ] unit-test

View File

@ -44,13 +44,13 @@ MIXIN: abstract-clumps
INSTANCE: abstract-clumps sequence INSTANCE: abstract-clumps sequence
M: abstract-clumps length M: abstract-clumps length
[ seq>> length 1 + ] [ n>> ] bi [-] ; inline [ seq>> length 1 + ] [ n>> ] bi - 1 max ; inline
M: abstract-clumps set-length M: abstract-clumps set-length
[ n>> + 1 - ] [ seq>> ] bi set-length ; inline [ n>> + 1 - ] [ seq>> ] bi set-length ; inline
M: abstract-clumps group@ 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 } ; TUPLE: chunking-seq { seq read-only } { n read-only } ;