]> gitweb.factorcode.org Git - factor.git/commitdiff
math.parser: (format-float) can only be flushable
authorBjörn Lindqvist <bjourne@gmail.com>
Sat, 8 Oct 2016 10:26:57 +0000 (12:26 +0200)
committerBjörn Lindqvist <bjourne@gmail.com>
Sat, 8 Oct 2016 22:47:37 +0000 (00:47 +0200)
basis/bootstrap/image/primitives/primitives.factor
core/math/parser/parser-tests.factor

index 7c149b9db92c2765bb82da590fbe7b35dc26280b..5ffd047ad624e80e95eaa334550c847b303b513b 100644 (file)
@@ -404,7 +404,7 @@ CONSTANT: all-primitives {
                 "(format-float)" ( n fill width precision format locale -- byte-array )
                 "format_float"
                 { float byte-array fixnum fixnum byte-array byte-array } { byte-array }
-                make-foldable
+                make-flushable
             }
         }
     }
index 4b8bbd1e358f0e23227769f00347a9ff6d31629b..24ccd1aab81efb3e54f545d9bcc45eb494b3eb1f 100644 (file)
@@ -1,4 +1,5 @@
-USING: layouts literals math math.parser.private sequences tools.test ;
+USING: kernel layouts literals math math.parser.private sequences
+strings tools.test ;
 IN: math.parser
 
 { f }
@@ -473,3 +474,16 @@ unit-test
 { "" } [
     33.4 "" 4 4 "f" "missing" format-float
 ] unit-test
+
+! Literal byte arrays are mutable, so (format-float) isn't foldable.
+: trouble ( -- str ba )
+    155000.0 B{ } -1 3 B{ 69 0 } [
+        B{ 67 0 } (format-float) >string
+    ] keep ;
+
+{
+    "1.55E+05"
+    "1.550e+05"
+} [
+    trouble CHAR: e 0 rot set-nth trouble drop
+] unit-test