sequences.repeating: fix repeat bug.
parent
378feb5324
commit
9e14799181
|
@ -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 } 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 1 2 2 2 2 3 3 3 3 } ] [ { 1 2 3 } 4 repeat ] unit-test
|
||||
|
|
|
@ -4,7 +4,9 @@
|
|||
USING: accessors circular kernel math sequences sequences.private ;
|
||||
IN: sequences.repeating
|
||||
|
||||
TUPLE: cycles circular length ;
|
||||
TUPLE: cycles
|
||||
{ circular circular read-only }
|
||||
{ length integer read-only } ;
|
||||
|
||||
: <cycles> ( seq length -- cycles )
|
||||
[ <circular> ] dip cycles boa ;
|
||||
|
@ -13,6 +15,7 @@ TUPLE: cycles circular length ;
|
|||
dupd <cycles> swap like ;
|
||||
|
||||
M: cycles length length>> ;
|
||||
|
||||
M: cycles set-length length<< ;
|
||||
|
||||
M: cycles virtual@ ( n seq -- n' seq' ) circular>> ;
|
||||
|
@ -21,7 +24,9 @@ M: cycles virtual-exemplar circular>> ;
|
|||
|
||||
INSTANCE: cycles virtual-sequence
|
||||
|
||||
TUPLE: repeats seq length ;
|
||||
TUPLE: repeats
|
||||
{ seq sequence read-only }
|
||||
{ length integer read-only } ;
|
||||
|
||||
: <repeats> ( seq times -- repeats )
|
||||
over length * repeats boa ;
|
||||
|
@ -31,6 +36,7 @@ TUPLE: repeats seq 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
|
||||
|
|
Loading…
Reference in New Issue