From 2fc1442771bf395fd1274cf4856957be7a140e3a Mon Sep 17 00:00:00 2001 From: Jon Harper Date: Sun, 28 Oct 2012 14:34:55 +0100 Subject: [PATCH] change clump when the group size is greater than the sequence length --- basis/grouping/grouping-docs.factor | 2 +- basis/grouping/grouping-tests.factor | 4 ++-- basis/grouping/grouping.factor | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/basis/grouping/grouping-docs.factor b/basis/grouping/grouping-docs.factor index 2b183c3364..dc81e3d3d8 100644 --- a/basis/grouping/grouping-docs.factor +++ b/basis/grouping/grouping-docs.factor @@ -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 } }" } } ; diff --git a/basis/grouping/grouping-tests.factor b/basis/grouping/grouping-tests.factor index 9340b322e2..104f9a7311 100644 --- a/basis/grouping/grouping-tests.factor +++ b/basis/grouping/grouping-tests.factor @@ -12,8 +12,8 @@ IN: grouping.tests >array ] unit-test -[ 0 ] [ { } 2 length ] unit-test -[ 0 ] [ { 1 } 2 length ] unit-test +[ 1 ] [ { } 2 length ] unit-test +[ 1 ] [ { 1 } 2 length ] unit-test [ 1 ] [ { 1 2 } 2 length ] unit-test [ 2 ] [ { 1 2 3 } 2 length ] unit-test diff --git a/basis/grouping/grouping.factor b/basis/grouping/grouping.factor index 83d48a14ad..ff13d1ab4b 100644 --- a/basis/grouping/grouping.factor +++ b/basis/grouping/grouping.factor @@ -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 } ;