read-number
2023-02-15
Reading numbers from an input stream.
Upstream URL
Author
License
read-number
Reading numbers from an input stream without using the Lisp reader.
Functions
read-integer (&optional input-stream eof-error-p eof-value recursivep &key unsigned-number plus-sign minus-sign group-separator radix)
Read an integer from an input stream.
read-float (&optional input-stream eof-error-p eof-value recursivep &key unsigned-number plus-sign minus-sign group-separator decimal-point exponent-marker float-format significand-radix exponent-radix exponent-base)
Read a floating-point number from an input stream.
Features
-
Optional arguments input-stream, eof-error-p, eof-value, and recursivep behave similar to
read
. -
Keyword argument unsigned-number controls the sign conventions; plus or minus sign, minus sign only (no explicit plus sign), or unsigned.
-
Keyword arguments plus-sign, minus-sign, group-separator, decimal-point, and exponent-marker denote character sets.
-
Keyword arguments significand-radix, exponent-radix, and exponent-base provide support for reading, for example, C99 hexadecimal floating-point literals.
-
Leading and trailing whitespace is not ignored.
-
Compatible with
with-input-from-string
.
Commentary
The read-integer
and read-float
functions are designed to read
external number representations. The read-number
function (to be
defined) is reserved for reading any Lisp number representation.
The functions provided by read-number are different to parse-number and parse-float because they read characters sequentially from a stream instead of parsing a string directly.