From: Alfredo Beaumont Date: Sat, 27 Apr 2013 20:39:40 +0000 (+0200) Subject: [reader] write a specific read-integer for reader X-Git-Url: http://repo.macrolet.net/gitweb/?a=commitdiff_plain;h=8bd012fce8d8b11ea3c66ca874373a550c08349f;p=jscl.git [reader] write a specific read-integer for reader --- 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)))))))