(read-string "01") returns 1.
In fact read-string from "01" to "07" returns the correct answer. But while we do (read-string "08") it throws an error:
NumberFormatException Invalid number: 08 clojure.lang.LispReader.readNumber (LispReader.java:330).
Can anyone plese help me to figure out why?"
If the string starts with a 0, then the number is read as an octal number: https://www.ascii.cl/conversion.htm
Thus, the table below, with some sample conversions:
If you had kept going you may have seen:
> (read-string "010")
8
Literal numbers beginning with 0 are taken to be octal (base 8). Hence the digit 8 is not valid.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With