(import (rnrs)) ;R6RS (import (rnrs base)) ;R6RS (import (scheme r5rs)) ;R7RS (import (scheme base)) ;R7RS
(string->number string) (string->number string radix)
Radix must be an exact integer object, either 2, 8, 10, or 16. If supplied, radix is a default radix that may be overridden by an explicit radix prefix in string (e.g., "#o177"). If radix is not supplied, then the default radix is 10.
If string is not a syntactically valid notation for a number, or would result in a number that the implementation cannot represent, then string->number returns #f. An error is never signaled due to the content of string.
(string->number "100") => 100 (string->number "100" 16) => 256 (string->number "1e2") => 100.0
In the following examples from R6RS an implementation may return #f instead of infinities or nans if they are not supported. It does not, like it otherwise would, raise the conditions from make-no-infinities-violation(3scm) or make-no-nans-violation(3scm).
(string->number "0/0") => #f (string->number "+inf.0") => +inf.0 (string->number "-inf.0") => -inf.0 (string->number "+nan.0") => +nan.0
The rules used by a particular implementation for string->number must also be applied to read and to the routine that reads programs, in order to maintain consistency between internal numeric processing, I/O, and the processing of programs. As a consequence, the R5RS permission to return #f when string has an explicit radix prefix has been withdrawn.
R6RS implementations are basically the same, except that they may lack support for infinities and nans. R7RS implementations have much more leeway:
The domain of string->number may be restricted by implementations in the following ways. If all numbers supported by an implementation are real, then string->number is permitted to return #f whenever string uses the polar or rectangular notations for complex numbers. If all numbers are integers, then string->number may return #f whenever the fractional notation is used. If all numbers are exact, then string->number may return #f whenever an exponent marker or explicit exactness prefix is used. If all inexact numbers are integers, then string->number may return #f whenever a decimal point is used.
https://github.com/schemedoc/manpages/
.