/[clarity]/decimal-number.lisp
ViewVC logotype

Contents of /decimal-number.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations)
Wed Aug 16 20:18:39 2006 UTC (7 years, 8 months ago) by skleinberg
File size: 985 byte(s)
Initial import
1 ;;Utility from Cliki: the common lisp wiki
2
3 ;(use-package "SPLIT-SEQUENCE")
4
5
6 (in-package "CLARITY")
7
8 (defun read-string-while (test &optional (stream *standard-input*) (eof-value nil) (recursive-p nil))
9 (coerce (loop as x = (peek-char nil stream nil eof-value recursive-p)
10 while (and (not (equal x eof-value)) (funcall test x))
11 collect (read-char stream nil eof-value recursive-p)) 'string))
12
13 (defun decimal-reader (s c n) (declare (ignore c n)) (parse-decimal (read-string-while #'constituentp s nil t)))
14
15 (defun parse-decimal (str)
16 (let* ((parts (split-sequence::split-sequence #\. str))
17 (a (car parts))
18 (b (cadr parts))
19 (a1 (parse-integer a))
20 (b1 (or (parse-integer (or b "0") :junk-allowed t) 0)))
21 (+ a1 (/ b1 (expt 10 (length b))))))
22
23 (defun use-decimal () (set-dispatch-macro-character #\# #\D #'decimal-reader *readtable*))
24
25
26 ;;; end of file -- decimal-number.lisp --

  ViewVC Help
Powered by ViewVC 1.1.5