]> gitweb.factorcode.org Git - factor.git/commitdiff
change behavior of circular-while
authorDoug Coleman <doug.coleman@gmail.com>
Tue, 8 Dec 2009 01:27:36 +0000 (19:27 -0600)
committerDoug Coleman <doug.coleman@gmail.com>
Tue, 8 Dec 2009 01:27:36 +0000 (19:27 -0600)
basis/circular/circular-docs.factor
basis/circular/circular.factor

index 2b4c083399757f4edbf49aba5fc64e2d35e444cd..93d137d626d3b377a5a734652029d14a815264ae 100644 (file)
@@ -50,7 +50,7 @@ HELP: rotate-circular
 
 HELP: circular-while
 { $values
-    { "sequence" sequence }
+    { "circular" circular }
     { "quot" quotation }
 }
 { $description "Calls " { $snippet "quot" } " on each element of the sequence until each call yields " { $link f } " in succession." } ;
index 67ddd3467b180e913d176330f3eeb967c7522fc8..58951f64c86066f31fdf2a585882f68435eff8c1 100644 (file)
@@ -59,27 +59,21 @@ PRIVATE>
 TUPLE: circular-iterator
     { circular read-only } { n integer } { last-start integer } ;
 
-: <circular-iterator> ( sequence -- obj )
-    <circular> 0 0 circular-iterator boa ; inline
+: <circular-iterator> ( circular -- obj )
+    0 0 circular-iterator boa ; inline
 
 <PRIVATE
 
 : (circular-while) ( iterator quot: ( obj -- ? ) -- )
-    [ [ [ n>> ] [ circular>> ] bi nth ] dip call ] 2keep rot [
-        [
-            [ 1 + ] change-n
-            dup n>> >>last-start
-        ] dip (circular-while)
+    [ [ [ n>> ] [ circular>> ] bi nth ] dip call ] 2keep
+    rot [ [ dup n>> >>last-start ] dip ] when
+    over [ n>> ] [ [ last-start>> ] [ circular>> length ] bi + 1 - ] bi = [
+        2drop
     ] [
-        over [ 1 + ] change-n
-        [ n>> ] [ [ last-start>> ] [ circular>> length ] bi + ] bi = [
-            2drop
-        ] [
-            (circular-while)
-        ] if
+        [ [ 1 + ] change-n ] dip (circular-while)
     ] if ; inline recursive
 
 PRIVATE>
 
-: circular-while ( sequence quot: ( obj -- ? ) -- )
-    [ <circular-iterator> ] dip (circular-while) ; inline
+: circular-while ( circular quot: ( obj -- ? ) -- )
+    [ clone ] dip [ <circular-iterator> ] dip (circular-while) ; inline