Add indices word

db4
Slava Pestov 2008-09-12 16:03:47 -05:00
parent d5140cf248
commit 996dd6442e
2 changed files with 8 additions and 1 deletions

View File

@ -265,4 +265,6 @@ M: bogus-hashcode hashcode* 2drop 0 >bignum ;
[ { 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
[ { 1 3 "X" 5 7 } ] [ "X" 2 { 1 3 5 7 } insert-nth ]
[ V{ 0 2 } ] [ "a" { "a" "b" "a" } indices ] unit-test

View File

@ -480,6 +480,11 @@ PRIVATE>
: last-index-from ( obj i seq -- n )
rot [ = ] curry find-last-from drop ;
: indices ( obj seq -- indices )
V{ } clone spin
[ rot = [ over push ] [ drop ] if ]
curry each-index ;
: nths ( seq indices -- seq' )
swap [ nth ] curry map ;