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:
2026-10-19 14:48:43 +03:00
parent cbf77c3e19
commit d8309f6ad8
2 changed files with 15 additions and 0 deletions

View File

@@ -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))