fix cursor 3map

db4
Doug Coleman 2009-06-22 11:55:42 -05:00
parent 166afc5784
commit 3afd2599ce
2 changed files with 10 additions and 4 deletions

View File

@ -37,3 +37,8 @@ IN: cursors.tests
[ { 111 222 } ] [ { 111 222 } ]
[ { 1 2 } { 10 20 } { 100 200 } [ + + ] 3map ] unit-test [ { 1 2 } { 10 20 } { 100 200 } [ + + ] 3map ] unit-test
: test-3map ( -- seq )
{ 1 2 } { 10 20 } { 100 200 } [ + + ] 3map ;
[ { 111 222 } ] [ test-3map ] unit-test

View File

@ -1,7 +1,7 @@
! Copyright (C) 2009 Slava Pestov, Doug Coleman. ! Copyright (C) 2009 Slava Pestov, Doug Coleman.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays generalizations kernel math sequences USING: accessors arrays generalizations kernel math sequences
sequences.private ; sequences.private fry ;
IN: cursors IN: cursors
GENERIC: cursor-done? ( cursor -- ? ) GENERIC: cursor-done? ( cursor -- ? )
@ -127,12 +127,13 @@ M: to-sequence cursor-write
: 2map ( seq1 seq2 quot -- ) [ cursor-map2 ] transform2 ; inline : 2map ( seq1 seq2 quot -- ) [ cursor-map2 ] transform2 ; inline
: find-done3? ( cursor1 cursor2 cursor3 quot -- ? ) : find-done3? ( cursor1 cursor2 cursor3 quot -- ? )
3 nover 3array [ cursor-done? ] any? [ 3 ndrop t ] swap '[ [ cursor-get-unsafe ] tri@ @ ]
[ 4 ndrop t ] [ [ [ cursor-get-unsafe ] tri@ ] dip call ] if ; inline [ 3 ndup 3 narray [ cursor-done? ] any? ] 2dip if ; inline
: cursor-until3 ( cursor cursor quot -- ) : cursor-until3 ( cursor cursor quot -- )
[ find-done3? not ] [ find-done3? not ]
[ drop [ cursor-advance ] tri@ ] bi-curry bi-curry bi-curry bi-curry while ; inline [ drop [ cursor-advance ] tri@ ]
bi-curry bi-curry bi-curry bi-curry while ; inline
: cursor-each3 ( cursor cursor quot -- ) : cursor-each3 ( cursor cursor quot -- )
[ f ] compose cursor-until3 ; inline [ f ] compose cursor-until3 ; inline