[cl-json-devel] Encoding DOUBLE-FLOAT
Robert Goldman
rpgoldman at sift.info
Sat Jun 25 15:01:05 UTC 2011
On 6/25/11 Jun 25 -1:24 AM, Boris Smilga wrote:
> On Fri, Jun 24, 2011 at 2:23 AM, Robert Goldman <rpgoldman at sift.info> wrote:
>
>> I was going to compare, e.g., MOST-POSITIVE-SHORT-FLOAT,
>> LEAST-NEGATIVE-SHORT-FLOAT and MOST-POSITIVE-SINGLE-FLOAT,
>> LEAST-NEGATIVE-SINGLE-FLOAT (at compile time) to attempt to determine if
>> SHORT-FLOAT and SINGLE-FLOAT are the same on the current implementation
>> and possibly conditionally-compile away the SINGLE-FLOAT type, and
>> similarly for DOUBLE- and LONG-....
>>
>> I would not be checking the numeric values of the number at run-time,
>> but the bounds on the types at compile time. Would that not work?
>
> Ah, yes, now I see. But then you might just write it
> straightforwardly as (subtypep 'short-float 'single-float), or vice
> versa. Since subtypes of float are either disjoint or synonymous,
> subtypep in this context effectively tests the types for equality.
>
> Still, I doubt the intended effect is worth the trouble. Having
> superfluous clauses in typecase is explicitly allowed: ‘[...] is
> permissible for more than one clause to specify a matching type’ (CLHS
> 5.3, definition of TYPECASE et al.) In fact, by trying to get rid of
> them beforehand we would be (re)doing the compiler's job. E. g., CCL
> eliminates them right there at macro expansion time:
>
> (macroexpand
> '(typecase foo
> (short-float #\S) (long-float #\L) (single-float #\F) (double-float #\D)))
> ⇒ (LET ((#:G4 FOO))
> (DECLARE (IGNORABLE #:G4))
> (COND ((TYPEP #:G4 'SHORT-FLOAT) NIL #\S)
> ((TYPEP #:G4 'LONG-FLOAT) NIL #\L)))
>
> Are we going to such lengths just in order to get rid of annoying
> warnings in a single implementation?
Yes. If these were simply style warnings, then I would agree with you.
However, they are not --- they are real, bona fide warnings, causing
COMPILE-FILE failure:
;Compiler warnings for "home:lisp;cl-json;src;encoder.lisp.newest" :
; In WRITE-JSON-NUMBER: Clause (SINGLE-FLOAT 'SINGLE-FLOAT) ignored in
ETYPECASE form - shadowed by (SHORT-FLOAT 'SHORT-FLOAT) .
; In WRITE-JSON-NUMBER: Clause (LONG-FLOAT 'LONG-FLOAT) ignored in
ETYPECASE form - shadowed by (DOUBLE-FLOAT 'DOUBLE-FLOAT) .
; Warning: COMPILE-FILE warned while performing #<COMPILE-OP (:FORCE T)
#x3020009CEB4D> on #<CL-SOURCE-FILE "cl-json" "src" "encoder">.
; While executing: #<STANDARD-METHOD ASDF:PERFORM (ASDF:COMPILE-OP
ASDF:CL-SOURCE-FILE)>, in process repl-thread(10).
; Warning: COMPILE-FILE failed while performing #<COMPILE-OP (:FORCE T)
#x3020009CEB4D> on #<CL-SOURCE-FILE "cl-json" "src" "encoder">.
; While executing: #<STANDARD-METHOD ASDF:PERFORM (ASDF:COMPILE-OP
ASDF:CL-SOURCE-FILE)>, in process repl-thread(10).
So I think these warnings must die.
I am inclined to think that these should simply be STYLE-WARNINGs, but
CCL does not agree with me.
Best,
r
More information about the cl-json-devel
mailing list