splitting: new word split-indices, it's useful compiler.cfg.scheduling so let's add it to the splitting vocab too
parent
96396cb3ad
commit
422c4b2051
|
@ -60,6 +60,17 @@ HELP: split-when-slice
|
||||||
{ $values { "seq" sequence } { "quot" { $quotation ( ... elt -- ... ? ) } } { "pieces" "a new array" } }
|
{ $values { "seq" sequence } { "quot" { $quotation ( ... elt -- ... ? ) } } { "pieces" "a new array" } }
|
||||||
{ $description "Splits " { $snippet "seq" } " at each occurrence of an element for which " { $snippet "quot" } " gives a true output and outputs an array of pieces as slices. The pieces do not include the elements along which the sequence was split." } ;
|
{ $description "Splits " { $snippet "seq" } " at each occurrence of an element for which " { $snippet "quot" } " gives a true output and outputs an array of pieces as slices. The pieces do not include the elements along which the sequence was split." } ;
|
||||||
|
|
||||||
|
HELP: split-indices
|
||||||
|
{ $values { "seq" sequence } { "indices" sequence } { "pieces" "a new array" } }
|
||||||
|
{ $description "Splits a sequence at the given indices." }
|
||||||
|
{ $examples
|
||||||
|
{ $example
|
||||||
|
"USING: prettyprint splitting ;"
|
||||||
|
"\"hello world\" { 3 6 } split-indices ."
|
||||||
|
"{ \"hel\" \"lo \" \"world\" }"
|
||||||
|
}
|
||||||
|
} ;
|
||||||
|
|
||||||
HELP: split
|
HELP: split
|
||||||
{ $values { "seq" sequence } { "separators" sequence } { "pieces" "a new array" } }
|
{ $values { "seq" sequence } { "separators" sequence } { "pieces" "a new array" } }
|
||||||
{ $description "Splits " { $snippet "seq" } " at each occurrence of an element of " { $snippet "separators" } " and outputs an array of pieces. The pieces do not include the elements along which the sequence was split." }
|
{ $description "Splits " { $snippet "seq" } " at each occurrence of an element of " { $snippet "separators" } " and outputs an array of pieces. The pieces do not include the elements along which the sequence was split." }
|
||||||
|
|
|
@ -104,3 +104,11 @@ unit-test
|
||||||
[ "afoobfooc" "" "" replace ] unit-test
|
[ "afoobfooc" "" "" replace ] unit-test
|
||||||
|
|
||||||
{ "" } [ "" "" "" replace ] unit-test
|
{ "" } [ "" "" "" replace ] unit-test
|
||||||
|
|
||||||
|
{ { "Thi" "s " "i" "s a sequence" } } [
|
||||||
|
"This is a sequence" { 3 5 6 } split-indices
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
{ { "" "This" } } [
|
||||||
|
"This" { 0 } split-indices
|
||||||
|
] unit-test
|
||||||
|
|
|
@ -100,6 +100,10 @@ PRIVATE>
|
||||||
: split-slice ( seq separators -- pieces )
|
: split-slice ( seq separators -- pieces )
|
||||||
[ member? ] curry split-when-slice ; inline
|
[ member? ] curry split-when-slice ; inline
|
||||||
|
|
||||||
|
: split-indices ( seq indices -- pieces )
|
||||||
|
over length suffix 0 swap [ dup swapd 2array ] map nip
|
||||||
|
[ first2 rot subseq ] with map ;
|
||||||
|
|
||||||
GENERIC: string-lines ( str -- seq )
|
GENERIC: string-lines ( str -- seq )
|
||||||
|
|
||||||
M: string string-lines
|
M: string string-lines
|
||||||
|
|
|
@ -1,15 +1,12 @@
|
||||||
USING: accessors alien alien.c-types alien.data arrays assocs bit-arrays
|
USING: accessors alien alien.c-types alien.data arrays assocs bit-arrays
|
||||||
bit-arrays.private classes.struct fry grouping kernel math math.statistics
|
bit-arrays.private classes.struct fry grouping kernel math math.statistics
|
||||||
sequences sequences.repeating vm words ;
|
sequences sequences.repeating splitting vm words ;
|
||||||
IN: tools.gc-decode
|
IN: tools.gc-decode
|
||||||
|
|
||||||
! Utils
|
! Utils
|
||||||
: byte-array>bit-array ( byte-array -- bit-array )
|
: byte-array>bit-array ( byte-array -- bit-array )
|
||||||
[ integer>bit-array 8 f pad-tail ] { } map-as concat ;
|
[ integer>bit-array 8 f pad-tail ] { } map-as concat ;
|
||||||
|
|
||||||
: split-indices ( seq indices -- parts )
|
|
||||||
over length suffix 0 prefix 2 clump [ first2 rot subseq ] with map ;
|
|
||||||
|
|
||||||
: (cut-points) ( counts times -- seq )
|
: (cut-points) ( counts times -- seq )
|
||||||
<repeats> cum-sum but-last ;
|
<repeats> cum-sum but-last ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue