From 36b8b56b2cd242203edd3ebd8dbdc08418b1ff5a Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Sat, 23 Mar 2013 11:38:05 -0700 Subject: [PATCH] grouping: Remove and and rename and to those. Fixes #765. --- basis/grouping/grouping-docs.factor | 21 ++++-------------- basis/grouping/grouping-tests.factor | 2 +- basis/grouping/grouping.factor | 32 +++++++++------------------- extra/grid-meshes/grid-meshes.factor | 2 +- extra/sequences/extras/extras.factor | 4 ++-- 5 files changed, 18 insertions(+), 43 deletions(-) diff --git a/basis/grouping/grouping-docs.factor b/basis/grouping/grouping-docs.factor index 571555e4e1..ff8a3f6ac4 100644 --- a/basis/grouping/grouping-docs.factor +++ b/basis/grouping/grouping-docs.factor @@ -11,9 +11,9 @@ ARTICLE: "grouping" "Groups and clumps" "Splitting a sequence into overlapping, fixed-length subsequences, wrapping around the end of the sequence:" { $subsections circular-clump } "A virtual sequence for splitting a sequence into overlapping, fixed-length subsequences:" -{ $subsections clumps } +{ $subsections clumps } "A virtual sequence for splitting a sequence into overlapping, fixed-length subsequences:" -{ $subsections circular-clumps } +{ $subsections circular-clumps } "The difference can be summarized as the following:" { $list { "With groups, the subsequences form the original sequence when concatenated:" @@ -97,7 +97,7 @@ $nl HELP: circular-clumps { $class-description "Instances are virtual sequences whose elements are overlapping fixed-length subsequences of an underlying sequence, beginning with every element in the original sequence and wrapping around its end. Circular clumps are mutable and resizable if the underlying sequence is mutable and resizable, respectively." $nl -"New clumps are created by calling " { $link } " and " { $link } "." } ; +"New clumps are created by calling " { $link } "." } ; HELP: clump { $values { "seq" "a sequence" } { "n" "a non-negative integer" } { "array" "a sequence of sequences" } } @@ -137,7 +137,7 @@ HELP: HELP: { $values { "seq" "a sequence" } { "n" "a non-negative integer" } { "clumps" clumps } } -{ $description "Outputs a virtual sequence whose elements are overlapping subsequences of " { $snippet "n" } " elements from the underlying sequence, starting with each of its elements and wrapping around the end of the sequence." } +{ $description "Outputs a virtual sequence whose elements are overlapping slices of " { $snippet "n" } " elements from the underlying sequence, starting with each of its elements and wrapping around the end of the sequence." } { $examples { $example "USING: kernel sequences grouping prettyprint ;" @@ -146,25 +146,12 @@ HELP: } } ; -HELP: -{ $values { "seq" "a sequence" } { "n" "a non-negative integer" } { "clumps" clumps } } -{ $description "Outputs a virtual sequence whose elements are overlapping slices of " { $snippet "n" } " elements from the underlying sequence, starting with each of its elements and wrapping around the end of the sequence." } -{ $examples - { $example - "USING: arrays kernel sequences grouping prettyprint ;" - "{ 1 2 3 4 } 3 third >array ." - "{ 3 4 1 }" - } -} ; - { clumps circular-clumps groups } related-words { clump circular-clump group } related-words { } related-words -{ } related-words - HELP: monotonic? { $values { "seq" sequence } { "quot" { $quotation "( elt1 elt2 -- ? )" } } { "?" "a boolean" } } { $description "Applies the relation to successive pairs of elements in the sequence, testing for a truth value. The relation should be a transitive relation, such as a total order or an equality relation." } diff --git a/basis/grouping/grouping-tests.factor b/basis/grouping/grouping-tests.factor index c90488ff29..a6e30d9d61 100644 --- a/basis/grouping/grouping-tests.factor +++ b/basis/grouping/grouping-tests.factor @@ -29,7 +29,7 @@ IN: grouping.tests [ 2 ] [ V{ } 2 1 over set-length seq>> length ] unit-test [ 3 ] [ V{ } 2 2 over set-length seq>> length ] unit-test -[ { { 1 2 } { 2 3 } } ] [ { 1 2 3 } 2 [ >array ] map ] unit-test +[ { { 1 2 } { 2 3 } } ] [ { 1 2 3 } 2 [ >array ] map ] unit-test [ f ] [ [ { } { } "Hello" ] all-equal? ] unit-test [ f ] [ [ { 2 } { } { } ] all-equal? ] unit-test diff --git a/basis/grouping/grouping.factor b/basis/grouping/grouping.factor index 0e604d5812..eb9fd54666 100644 --- a/basis/grouping/grouping.factor +++ b/basis/grouping/grouping.factor @@ -72,22 +72,22 @@ INSTANCE: groups abstract-groups groups new-groups ; inline TUPLE: clumps < chunking-seq ; -INSTANCE: clumps subseq-chunking +INSTANCE: clumps slice-chunking INSTANCE: clumps abstract-clumps : ( seq n -- clumps ) clumps new-groups ; inline -TUPLE: sliced-clumps < chunking-seq ; -INSTANCE: sliced-clumps slice-chunking -INSTANCE: sliced-clumps abstract-clumps + ( seq n -- clumps ) - sliced-clumps new-groups ; inline +: map-like ( seq n quot -- seq ) + 2keep drop '[ _ like ] map ; inline -: group ( seq n -- array ) [ ] 2keep drop '[ _ like ] map ; +PRIVATE> -: clump ( seq n -- array ) { } like ; +: group ( seq n -- array ) [ ] map-like ; inline + +: clump ( seq n -- array ) [ ] map-like ; inline : monotonic? ( seq quot: ( elt1 elt2 -- ? ) -- ? ) over length dup 2 < [ 3drop t ] [ @@ -120,18 +120,6 @@ M: circular-slice virtual@ C: circular-slice -TUPLE: sliced-circular-clumps < chunking-seq ; -INSTANCE: sliced-circular-clumps sequence - -M: sliced-circular-clumps length - seq>> length ; inline - -M: sliced-circular-clumps nth - [ n>> over + ] [ seq>> ] bi ; inline - -: ( seq n -- clumps ) - sliced-circular-clumps new-groups ; inline - TUPLE: circular-clumps < chunking-seq ; INSTANCE: circular-clumps sequence @@ -139,10 +127,10 @@ M: circular-clumps length seq>> length ; inline M: circular-clumps nth - [ n>> over + ] [ seq>> ] bi [ ] [ like ] bi ; inline + [ n>> over + ] [ seq>> ] bi ; inline : ( seq n -- clumps ) circular-clumps new-groups ; inline : circular-clump ( seq n -- array ) - { } like ; inline + [ ] map-like ; inline \ No newline at end of file diff --git a/extra/grid-meshes/grid-meshes.factor b/extra/grid-meshes/grid-meshes.factor index 47f649868e..092a3e35d1 100644 --- a/extra/grid-meshes/grid-meshes.factor +++ b/extra/grid-meshes/grid-meshes.factor @@ -16,7 +16,7 @@ TUPLE: grid-mesh dim buffer row-length ; : vertex-array ( dim -- vertices ) first2 [ [ 0.0 1.0 1.0 ] dip /f ] bi@ - 2 [ first2 vertex-array-row ] with map concat ; + 2 [ first2 vertex-array-row ] with map concat ; : >vertex-buffer ( bytes -- buffer ) [ GL_ARRAY_BUFFER ] dip GL_STATIC_DRAW ; inline diff --git a/extra/sequences/extras/extras.factor b/extra/sequences/extras/extras.factor index 87704d7d55..60d8b43863 100644 --- a/extra/sequences/extras/extras.factor +++ b/extra/sequences/extras/extras.factor @@ -32,7 +32,7 @@ IN: sequences.extras [ swap ] 2dip each-from ; inline : all-subseqs ( seq -- seqs ) - dup length [1,b] [ ] with map concat ; + dup length [1,b] [ clump ] with map concat ; :: each-subseq ( ... seq quot: ( ... x -- ... ) -- ... ) seq length :> len @@ -49,7 +49,7 @@ IN: sequences.extras : filter-all-subseqs-range ( ... seq range quot: ( ... x -- ... ) -- seq ) [ - '[ _ filter ] with map concat + '[ _ filter ] with map concat ] 3keep 2drop map-like ; inline : filter-all-subseqs ( ... seq quot: ( ... x -- ... ) -- seq )