Subject: Re: Show me a better way?
From: (Rob Warnock)
Date: Sun, 01 Mar 2009 21:10:18 -0600
Newsgroups: comp.lang.lisp
Message-ID: <>
D Herring  <> wrote:
| Pillsy wrote:
| > (defmethod something-mathematical ((x integer) (y double-float))
| >   ...)
| > is also perfectly legit.
| Check again...  Param specializers are a symbol (naming a class), a
| class, or an eql form.  The numeric types are not necessarily classes
| (some implementations support this, but its not required).

Hmmm... I think you're somewhat less than half right here. True, the
CLHS does not define a System Class for DOUBLE-FLOAT per se [or any
of the other various precisions of floats], but it *does* for FLOAT:
    System Class FLOAT
    Class Precedence List:
    float, real, number, t 

and, of course, also for INTEGER:
    System Class INTEGER
    Class Precedence List:
    integer, rational, real, number, t 

In fact, AFAICT a conforming CL *must* provide a System Class for -- and
thus be able to dispatch on -- at least INTEGER, RATIO, FLOAT, COMPLEX
and all of their their superclasses (e.g., RATIONAL, REAL, NUMBER).

The reason [again, AFAICT] that a conforming CL need not provide
System Classes for the ${PRECISION}-FLOAT subtypes of FLOAT is that
the ANSI Standard permits them to be degenerate, see:
    short-float:   short-float, float, real, number, t
    single-float: single-float, float, real, number, t
    double-float: double-float, float, real, number, t
    long-float:     long-float, float, real, number, t 
    There can be fewer than four internal representations for floats.
    - If there is only one, it is the type single-float. In this
      representation, an object is simultaneously of types
      single-float, double-float, short-float, and long-float.

Given that, the standard *can't* mandate that (say) SINGLE-FLOAT and
DOUBLE-FLOAT dispatch differently, since they might be identical types.

| IIRC, Clisp does not support numeric specializers.

Again, only half-correct. Older CLISPs did not allow specializers
of the ${PRECISION}-FLOAT subtypes of FLOAT [newer versions may be
more liberal, I dunno], but certainly *did* allow numeric types
which are system classes:

    $ clisp -q
    [1]> (defmethod types ((x integer) (y float))
	   (list (list x 'is (type-of x)) (list y 'is (type-of y))))
    [2]> (types 3 4.0)
    [3]> (types 3 4d0)
    ((3 IS FIXNUM) (4.0d0 IS DOUBLE-FLOAT))

Other CLs also do allow some degree of ${PRECISION}-FLOAT specializers,
e.g., CMUCL-19e on x86 permits specializing on SINGLE-FLOAT & DOUBLE-FLOAT
[and provides System Classes for those], but *not* on either SHORT-FLOAT
or LONG-FLOAT [which are degenerate with SINGLE-FLOAT & DOUBLE-FLOAT,

| P.S.  This is one of the things which should have been fixed in the 
| past 10 years...

See above for why it's not "broken".  (IMHO, YMMV.)


Rob Warnock			<>
627 26th Avenue			<URL:>
San Mateo, CA 94403		(650)572-2607