Move partition combinator into core

db4
Slava Pestov 2008-09-05 19:32:19 -05:00
parent aea0fed14c
commit 6792ff748e
3 changed files with 15 additions and 9 deletions

View File

@ -260,3 +260,9 @@ TUPLE: bogus-hashcode ;
M: bogus-hashcode hashcode* 2drop 0 >bignum ;
[ 0 ] [ { T{ bogus-hashcode } } hashcode ] unit-test
[ { 2 4 6 } { 1 3 5 7 } ] [ { 1 2 3 4 5 6 7 } [ even? ] partition ] unit-test
[ { 1 3 7 } ] [ 2 { 1 3 5 7 } remove-nth ] unit-test
[ { 1 3 "X" 5 7 } ] [ "X" 2 { 1 3 5 7 } insert-nth ] unit-test

View File

@ -426,6 +426,15 @@ PRIVATE>
: filter ( seq quot -- subseq )
over >r pusher >r each r> r> like ; inline
: push-either ( elt quot accum1 accum2 -- )
>r >r keep swap r> r> ? push ; inline
: 2pusher ( quot -- quot accum1 accum2 )
V{ } clone V{ } clone [ [ push-either ] 3curry ] 2keep ; inline
: partition ( seq quot -- trueseq falseseq )
over >r 2pusher >r >r each r> r> r> tuck [ like ] 2bi@ ; inline
: monotonic? ( seq quot -- ? )
>r dup length 1- swap r> (monotonic) all? ; inline

View File

@ -135,15 +135,6 @@ PRIVATE>
: power-set ( seq -- subsets )
2 over length exact-number-strings swap [ switches ] curry map ;
: push-either ( elt quot accum1 accum2 -- )
>r >r keep swap r> r> ? push ; inline
: 2pusher ( quot -- quot accum1 accum2 )
V{ } clone V{ } clone [ [ push-either ] 3curry ] 2keep ; inline
: partition ( seq quot -- trueseq falseseq )
over >r 2pusher >r >r each r> r> r> drop ; inline
: cut-find ( seq pred -- before after )
dupd find drop dup [ cut ] when ;