Fix stack effects

Add take-while
release
Doug Coleman 2007-11-30 20:23:27 -06:00
parent db3fbb52b2
commit 159dd697e4
2 changed files with 8 additions and 3 deletions

View File

@ -41,3 +41,4 @@ math.functions tools.test ;
[ V{ } [ delete-random drop ] keep length ] unit-test-fails
[ { 1 9 25 } ] [ { 1 3 5 6 } [ sq ] [ even? ] map-until ] unit-test
[ { 2 4 } ] [ { 2 4 1 3 } [ even? ] take-while ] unit-test

View File

@ -63,10 +63,14 @@ IN: sequences.lib
: delete-random ( seq -- value )
[ length random ] keep [ nth ] 2keep delete-nth ;
: (map-until) ( quot pred -- )
: (map-until) ( quot pred -- quot )
[ dup ] swap 3compose
[ [ drop t ] [ , f ] if ] compose [ find 2drop ] curry ;
: map-until ( seq quot pred -- )
#! Example: { 1 3 5 6 } [ sq ] [ even? ] map-until . -> { 1 9 25 }
: map-until ( seq quot pred -- newseq )
(map-until) { } make ;
: take-while ( seq quot -- newseq )
[ not ] compose
[ find drop [ head-slice ] when* ] curry
[ dup ] swap compose keep like ;