]> gitweb.factorcode.org Git - factor.git/commitdiff
math.extras: moving until-zero to math.
authorJohn Benediktsson <mrjbq7@gmail.com>
Mon, 7 Dec 2020 18:25:52 +0000 (10:25 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Mon, 7 Dec 2020 18:25:52 +0000 (10:25 -0800)
core/math/math-docs.factor
core/math/math.factor
extra/math/extras/extras.factor

index 4be97fdf48dad7ac17799ae4e8e53e3fa7081463..43094d35cc5d5f7742efcb8f692b44f3b0b612ad 100644 (file)
@@ -309,6 +309,18 @@ HELP: unless-zero
     }
 } ;
 
+HELP: until-zero
+{ $values
+     { "n" number } { "quot" { $quotation ( ... x -- ... y ) } } }
+{ $description "Makes a check if the number is zero, and repeatedly calls " { $snippet "quot" } " until the value on the stack is zero." }
+{ $examples
+    { $example
+    "USING: kernel math prettyprint ;"
+    "15 [ dup . 2/ ] until-zero"
+    "15\n7\n3\n1"
+    }
+} ;
+
 HELP: times
 { $values { "n" integer } { "quot" quotation } }
 { $description "Calls the quotation " { $snippet "n" } " times." }
index 6c66e7d9e3dfa0cd191ad0398b2f33c240b694bf..de463a357915081702e122787d9f4d428d6acd08 100644 (file)
@@ -156,6 +156,8 @@ GENERIC: neg? ( x -- ? )
 
 : unless-zero ( ... n quot: ( ... n -- ... ) -- ... ) [ ] swap if-zero ; inline
 
+: until-zero ( ... n quot: ( ... x -- ... y ) -- ... ) [ dup zero? ] swap until drop ; inline
+
 UNION: integer fixnum bignum ;
 
 TUPLE: ratio
index 9a986a979f849d298dbd8b68ec5bc76ed103b7df..9db8c9c6f9a628008924163b11bb32bab3846fc4 100644 (file)
@@ -161,9 +161,6 @@ PRIVATE>
 : sinc ( x -- y )
     [ 1 ] [ pi * [ sin ] [ / ] bi ] if-zero ;
 
-: until-zero ( n quot -- )
-    [ dup zero? ] swap until drop ; inline
-
 : cum-reduce ( seq identity quot: ( prev elt -- next ) -- result cum-result )
     [ dup rot ] dip dup '[ _ curry dip dupd @ ] each ; inline