When a token is read, it is interpreted as a number or symbol. The token is interpreted as a number if it satisfies the syntax for numbers specified in the next figure.
|
Figure 2.9: Syntax for Numeric Tokens
sign—a sign.
slash—a slash
decimal-point—a dot.
exponent-marker—an exponent marker.
decimal-digit—a digit in radix 10
.
digit—a digit in the current input radix.
To allow implementors and future Common Lisp standards to extend the syntax of numbers, a syntax for potential numbers is defined that is more general than the syntax for numbers. A token is a potential number if it satisfies all of the following requirements:
.
),
extension characters (^ or _
),
and number markers.
A number marker is a letter.
Whether a letter may be treated as a number marker depends on context,
but no letter that is adjacent to another letter may ever be treated as a number marker.
Exponent markers are number markers.
but not a
package marker.
The syntax involving a leading
package marker followed by a potential number is
not well-defined. The consequences of the use
of notation such as :1
, :1/2
, and :2^3
in a
position where an expression appropriate for read
is expected are unspecified.
If a potential number has number syntax,
a number of the appropriate type is constructed and returned,
if the number is representable in an implementation.
A number will not be representable in an implementation
if it is outside the boundaries set by the implementation-dependent
constants for numbers.
For example, specifying too large or too small an exponent for a float
may make the number impossible to represent in the implementation.
A ratio with denominator zero (such as -35/000
)
is not represented in any implementation.
When a token with the syntax of a number cannot be converted to an internal
number, an error of type reader-error
is signaled. An error
must not be signaled for specifying too many significant digits
for a float; a truncated or rounded value should be produced.
If there is an ambiguity as to whether a letter should be treated as a digit or as a number marker, the letter is treated as a digit.
A potential number cannot contain any escape characters. An escape character robs the following character of all syntactic qualities, forcing it to be strictly alphabetic2 and therefore unsuitable for use in a potential number. For example, all of the following representations are interpreted as symbols, not numbers:
\256 25\64 1.0\E6 |100| 3\.14159 |3/4| 3\/4 5||
In each case, removing the escape character (or characters) would cause the token to be a potential number.
As examples, the tokens in the next figure are potential numbers, but they are not actually numbers, and so are reserved tokens; a conforming implementation is permitted, but not required, to define their meaning.
|
Figure 2.10: Examples of reserved tokens
The tokens in the next figure are not potential numbers; they are always treated as symbols:
The tokens in the next figure are potential numbers
if the current input base is 16
,
but they are always treated as symbols if the current input base is 10
.