sequences.repeating: fix repeat bug.

db4
John Benediktsson 2012-08-09 15:07:45 -07:00
parent 378feb5324
commit 9e14799181
2 changed files with 12 additions and 3 deletions

View File

@ -5,4 +5,7 @@ IN: sequences.repeating.tests
[ { 1 2 3 1 2 3 1 2 3 } ] [ { 1 2 3 } 9 cycle ] unit-test [ { 1 2 3 1 2 3 1 2 3 } ] [ { 1 2 3 } 9 cycle ] unit-test
[ { } ] [ { 1 2 3 } 0 repeat ] unit-test [ { } ] [ { 1 2 3 } 0 repeat ] unit-test
[ { 1 2 3 } ] [ { 1 2 3 } 1 repeat ] unit-test
[ { 1 1 2 2 3 3 } ] [ { 1 2 3 } 2 repeat ] unit-test
[ { 1 1 1 2 2 2 3 3 3 } ] [ { 1 2 3 } 3 repeat ] unit-test [ { 1 1 1 2 2 2 3 3 3 } ] [ { 1 2 3 } 3 repeat ] unit-test
[ { 1 1 1 1 2 2 2 2 3 3 3 3 } ] [ { 1 2 3 } 4 repeat ] unit-test

View File

@ -4,7 +4,9 @@
USING: accessors circular kernel math sequences sequences.private ; USING: accessors circular kernel math sequences sequences.private ;
IN: sequences.repeating IN: sequences.repeating
TUPLE: cycles circular length ; TUPLE: cycles
{ circular circular read-only }
{ length integer read-only } ;
: <cycles> ( seq length -- cycles ) : <cycles> ( seq length -- cycles )
[ <circular> ] dip cycles boa ; [ <circular> ] dip cycles boa ;
@ -13,6 +15,7 @@ TUPLE: cycles circular length ;
dupd <cycles> swap like ; dupd <cycles> swap like ;
M: cycles length length>> ; M: cycles length length>> ;
M: cycles set-length length<< ; M: cycles set-length length<< ;
M: cycles virtual@ ( n seq -- n' seq' ) circular>> ; M: cycles virtual@ ( n seq -- n' seq' ) circular>> ;
@ -21,7 +24,9 @@ M: cycles virtual-exemplar circular>> ;
INSTANCE: cycles virtual-sequence INSTANCE: cycles virtual-sequence
TUPLE: repeats seq length ; TUPLE: repeats
{ seq sequence read-only }
{ length integer read-only } ;
: <repeats> ( seq times -- repeats ) : <repeats> ( seq times -- repeats )
over length * repeats boa ; over length * repeats boa ;
@ -31,6 +36,7 @@ TUPLE: repeats seq length ;
M: repeats length length>> ; M: repeats length length>> ;
M: repeats nth-unsafe seq>> [ length /i ] keep nth ; M: repeats nth-unsafe
[ length>> / ] [ seq>> [ length * >integer ] keep nth ] bi ;
INSTANCE: repeats immutable-sequence INSTANCE: repeats immutable-sequence