]> gitweb.factorcode.org Git - factor.git/commitdiff
sequences.extras: make rotate support negative n.
authorJohn Benediktsson <mrjbq7@gmail.com>
Mon, 4 Apr 2016 18:05:28 +0000 (11:05 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Mon, 4 Apr 2016 18:05:28 +0000 (11:05 -0700)
extra/sequences/extras/extras-tests.factor
extra/sequences/extras/extras.factor

index 3d7c4ff36cf0f994d3e398c0dae1e178871f3694..dfdc2837f9ea928742bcb85825741b7784d13d6f 100644 (file)
@@ -75,7 +75,7 @@ IN: sequences.extras.tests
 
 { "hello" "hello" } [ "hello" dup 0 rotate ] unit-test
 { "hello" "llohe" } [ "hello" dup 2 rotate ] unit-test
-[ "hello" dup -1 rotate ] must-fail
+{ "hello" "ohell" } [ "hello" dup -1 rotate ] unit-test
 
 { "hello" } [ "hello" dup 0 rotate! ] unit-test
 { "lohel" } [ "hello" dup 3 rotate! ] unit-test
index 6aca1b284c9f734d2732e0c87ca0ae1ae5be7863..b37ca03bd568e18575a4923dc3941256e06a28c5 100644 (file)
@@ -196,7 +196,7 @@ ERROR: slices-don't-touch slice1 slice2 ;
     ] if ;
 
 : rotate ( seq n -- seq' )
-    cut prepend ;
+    dup 0 > [ cut ] [ abs cut* ] if prepend ;
 
 :: rotate! ( seq n -- )
     n seq bounds-check length :> end