]> gitweb.factorcode.org Git - factor.git/commitdiff
rotate-circular word
authorJoe Groff <arcata@gmail.com>
Thu, 14 May 2009 00:31:58 +0000 (19:31 -0500)
committerJoe Groff <arcata@gmail.com>
Thu, 14 May 2009 00:31:58 +0000 (19:31 -0500)
basis/circular/circular-docs.factor
basis/circular/circular-tests.factor
basis/circular/circular.factor

index c7af57c1feba64ada3bd3fd04d596eb12b5540e4..235d5db2c7b5df4945b4630fb18db03ca38dae9e 100644 (file)
@@ -43,6 +43,11 @@ HELP: push-growing-circular
      { "elt" object } { "circular" circular } }
 { $description "Pushes an element onto a " { $link growing-circular } " object." } ;
 
+HELP: rotate-circular
+{ $values
+    { "circular" circular } }
+{ $description "Advances the start index of a circular object by one." } ;
+
 ARTICLE: "circular" "Circular sequences"
 "The " { $vocab-link "circular" } " vocabulary implements the " { $link "sequence-protocol" } " to allow an arbitrary start index and wrap-around indexing." $nl
 "Creating a new circular object:"
@@ -51,6 +56,7 @@ ARTICLE: "circular" "Circular sequences"
 { $subsection <growing-circular> }
 "Changing the start index:"
 { $subsection change-circular-start }
+{ $subsection rotate-circular }
 "Pushing new elements:"
 { $subsection push-circular }
 { $subsection push-growing-circular } ;
index 105e3790aa9b4b8d240b6c7caeb8bb452ba78155..3a94e14640d8614f0a4bbe7efdb4719486186765 100644 (file)
@@ -12,6 +12,7 @@ circular strings ;
 [ CHAR: e ] [ "test" <circular> 5 swap nth-unsafe ] unit-test
  
 [ [ 1 2 3 ] ] [ { 1 2 3 } <circular> [ ] like ] unit-test
+[ [ 2 3 1 ] ] [ { 1 2 3 } <circular> [ rotate-circular ] keep [ ] like ] unit-test
 [ [ 2 3 1 ] ] [ { 1 2 3 } <circular> 1 over change-circular-start [ ] like ] unit-test
 [ [ 3 1 2 ] ] [ { 1 2 3 } <circular> 1 over change-circular-start 1 over change-circular-start [ ] like ] unit-test
 [ [ 3 1 2 ] ] [ { 1 2 3 } <circular> -100 over change-circular-start [ ] like ] unit-test
index 9f3a71f2a81b6f747d49f8badad6257ec5664a49..909b2ed713727a27fea76b902cbb1f7f5151d5a3 100644 (file)
@@ -27,6 +27,9 @@ M: circular virtual-seq seq>> ;
     #! change start to (start + n) mod length
     circular-wrap (>>start) ;
 
+: rotate-circular ( circular -- )
+    [ start>> 1 + ] keep circular-wrap (>>start) ;
+
 : push-circular ( elt circular -- )
     [ set-first ] [ 1 swap change-circular-start ] bi ;