From 8bd012fce8d8b11ea3c66ca874373a550c08349f Mon Sep 17 00:00:00 2001 From: Alfredo Beaumont Date: Sat, 27 Apr 2013 22:39:40 +0200 Subject: [PATCH] [reader] write a specific read-integer for reader --- src/read.lisp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/read.lisp b/src/read.lisp index c99604a..ae56e94 100644 --- a/src/read.lisp +++ b/src/read.lisp @@ -163,6 +163,24 @@ (intern name package) (find-symbol name package)))) +(defun read-integer (string) + (let ((sign 1) + (number nil) + (size (length string))) + (dotimes (i size) + (let ((elt (char string i))) + (cond + ((digit-char-p elt) + (setq number (+ (* (or number 0) 10) (digit-char-p elt)))) + ((zerop i) + (case elt + (#\+ nil) + (#\- (setq sign -1)) + (otherwise (return-from read-integer)))) + ((and (= i (1- size)) (char= elt #\.)) nil) + (t (return-from read-integer))))) + (and number (* sign number)))) + (defun read-float (string) (block nil (let ((sign 1) @@ -304,7 +322,7 @@ (read-sharp stream)) (t (let ((string (read-until stream #'terminalp))) - (or (values (!parse-integer string nil)) + (or (read-integer string) (read-float string) (read-symbol string))))))) -- 1.7.10.4