refuse an integer with a leading 0
017 is 17 to Scheme and 15 to C, so whoever reads the Sex and whoever reads the C would each take it for something else.
This commit is contained in:
@@ -198,6 +198,12 @@
|
||||
|
||||
(define (finish-atom s)
|
||||
(let ((digits (if (substring-index "_" s) (or (ungrouped s (or (c-radix s) 10)) s) s)))
|
||||
;; 017 is 17 to Scheme and 15 to C: whoever reads the Sex and whoever
|
||||
;; reads the C would each take it for something else
|
||||
(when (irregex-match "-?0[0-9]+[uUlL]*" digits)
|
||||
(error
|
||||
"a leading 0 is octal to C; write the number without it, or #o for octal"
|
||||
s))
|
||||
(cond
|
||||
((string=? s ".") dot-token)
|
||||
((or (string->number digits) (radix-number digits))
|
||||
|
||||
@@ -74,6 +74,15 @@
|
||||
"1_000_000 0xFF_FF 0b1010_0101 1_000.5 -1_000 1e0_5 #x80_00")
|
||||
(reader-test '(_1 1_ 1__0 0x_FF 0xF_p) "_1 1_ 1__0 0x_FF 0xF_p")
|
||||
|
||||
;; 017 is 17 to Scheme and 15 to C, so it means one thing to whoever
|
||||
;; reads the Sex and another to whoever reads the C
|
||||
(test "a leading 0 is refused"
|
||||
"a leading 0 is octal to C; write the number without it, or #o for octal"
|
||||
(read-error "017"))
|
||||
(test "with a suffix as well" #t (string? (read-error "017u")))
|
||||
(test "or grouped" #t (string? (read-error "0_17")))
|
||||
(reader-test '(0 0.5 15) "0 00.5 #o17")
|
||||
|
||||
;; Scheme reads numbers C has no literal for, and they reached C as
|
||||
;; written: 1/2 is integer division there, and +inf.0 no number at all
|
||||
(test "a ratio is not a C number"
|
||||
|
||||
Reference in New Issue
Block a user