sequences: fix filter! to allow stack arguments to be used by the quot.

char-rename
John Benediktsson 2017-03-05 14:09:03 -08:00
parent c6a00bfdfe
commit 44da4ed4dd
2 changed files with 2 additions and 1 deletions

View File

@ -93,6 +93,7 @@ IN: sequences.tests
{ V{ 4 2 6 } } [ V{ 1 4 2 5 3 6 } clone [ 2 mod 0 = ] filter! ] unit-test
{ V{ 3 } } [ V{ 1 2 3 } clone 2 [ swap < ] curry filter! ] unit-test
{ 4 V{ 1 2 3 } } [ 4 V{ 1 4 2 5 3 6 } [ dupd > ] filter! ] unit-test
{ "hello world how are you" }
[ { "hello" "world" "how" "are" "you" } " " join ] unit-test

View File

@ -724,7 +724,7 @@ M: slice equal? over slice? [ sequence= ] [ 2drop f ] if ;
: (filter!) ( ... quot: ( ... elt -- ... ? ) store scan seq -- ... )
2dup length < [
[ move-unsafe ] 3keep
[ nth-unsafe pick call [ 1 + ] when ] 2keep
[ nth-unsafe -rot [ [ call ] keep ] dip rot [ 1 + ] when ] 2keep
[ 1 + ] dip
(filter!)
] [ nip set-length drop ] if ; inline recursive