[cl-json-devel] Encoding DOUBLE-FLOAT
Robert Goldman
rpgoldman at sift.info
Thu Jun 23 01:04:10 UTC 2011
On 6/22/11 Jun 22 -6:25 PM, Boris Smilga wrote:
> (defun write-json-number (nr stream)
> "Write the JSON representation of the number NR to STREAM."
> (typecase nr
> (integer (format stream "~d" nr))
> (real (let ((*read-default-float-format*
> (typecase nr
> (long-float 'long-float)
> (double-float 'double-float)
> (short-float 'short-float)
> (t 'single-float))))
> (format stream "~f" nr)))
> (t (unencodable-value-error nr 'write-json-number))))
I agree that this is better, but when I compile this in Clozure on a 64
bit Intel Mac, I get this warning:
;Compiler warnings for "/Users/rpg/lisp/cl-json/src/encoder.lisp" :
; In WRITE-JSON-NUMBER: Clause (DOUBLE-FLOAT 'DOUBLE-FLOAT) ignored in
TYPECASE form - shadowed by (LONG-FLOAT 'LONG-FLOAT)
Would it be better to rewrite this from shortest to longest as:
(defun write-json-number (nr stream)
"Write the JSON representation of the number NR to STREAM."
(typecase nr
(integer (format stream "~d" nr))
(real (let ((*read-default-float-format*
(etypecase nr
(short-float 'short-float)
(single-float 'single-float)
(double-float 'double-float)
(long-float 'long-float))))
(format stream "~f" nr)))
(t (unencodable-value-error nr 'write-json-number))))
This still yields warnings on Clozure, because SHORT-FLOAT ==
SINGLE-FLOAT and DOUBLE-FLOAT == LONG-FLOAT (IIUC), but I think that's
implementation-dependent, so we can't do away with the intermediates in
general, can we?
Not sure how to muffle these warnings, or even if it's desirable, since
the Clozure implementers might split apart single and short and double
and long at some point, right?
Best,
r
More information about the cl-json-devel
mailing list