Closed kpoeck closed 4 years ago
That seems to work:
(defun make-integer-accumulator (base)
(let ((value 0))
(lambda (&optional char invalidatep)
(if char
(let ((digit (digit-char-p char base)))
(cond ((not (null digit))
(when (numberp value)
(setf value (+ (* value base) digit))))
(invalidatep
(setf value nil))
(t
nil)))
value))))
http://www.lispworks.com/documentation/lw51/CLHS/Body/v_rd_bas.htm
The value of read-base, called the current input base, is the radix in which integers and ratios are to be read by the Lisp reader. The parsing of other numeric types (e.g., floats) is not affected by this option.
Should return 2140.969.
The error is in make-integer-accumulator once value is nil, and the next call gives a valid digit, it will (* value base) with value = nil.
e.g.: