From: Raymond Toy
Subject: Method specializing on (complex double-float)?
Date: 
Message-ID: <4nln1k3mnt.fsf@rtp.ericsson.se>
Is it possible to have a method specializing on (complex
double-float)?

The CLHS says the parameter specializer has to be a symbol or (eql
<stuff>), so, strictly, you can't.  

Is there some other way of doing this?

Ray

From: Tunc Simsek
Subject: Re: Method specializing on (complex double-float)?
Date: 
Message-ID: <39174610.6D4B9802@robotics.eecs.berkeley.edu>
yes, at least a hack in CMUCL.  See the file mplus.lisp in matlisp:


(defmethod m+! ((a kernel::complex-double-float) (b complex-matrix))
  (m+! b a))

Regards,
Tunc

Raymond Toy wrote:
> 
> Is it possible to have a method specializing on (complex
> double-float)?
> 
> The CLHS says the parameter specializer has to be a symbol or (eql
> <stuff>), so, strictly, you can't.
> 
> Is there some other way of doing this?
> 
> Ray
From: Raymond Toy
Subject: Re: Method specializing on (complex double-float)?
Date: 
Message-ID: <4npuqvx33i.fsf@rtp.ericsson.se>
>>>>> "Tunc" == Tunc Simsek <······@robotics.eecs.berkeley.edu> writes:

    Tunc> yes, at least a hack in CMUCL.  See the file mplus.lisp in matlisp:

That's what I was trying to avoid.  Hacks.

Ray
From: David Bakhash
Subject: Re: Method specializing on (complex double-float)?
Date: 
Message-ID: <m3ln1idd5x.fsf@alum.mit.edu>
well, I think the moral of the story there is that method specializers
are not just symbols, but they name classes (of course, I'm
disregarding the (eql <stuff>) case.

Even with deftype, naming your own intermediate types for things like
(complex single-float), you can't specialize on fields of the complex
number.  I don't think this is really a limitation in Lisp; I think
it's like that for reasons that make implementation feasible.  It's
nice enough that you can specialize methods on built-in types at all.

This is simply a case in which you have to further "specialize" your
functions within the method, if you want to.  For example, a typecase
inside the method that is specialized for complex numbers.  Not as
pretty, but it works.  Of course, if you have to go that route, you
might can the typecase alltogether.  I think that if you're looking
at the types inside the complex number, then you're going to be doing
a lot of type checking, and that's not so efficient anyway.

dave
From: SRS
Subject: Re: Method specializing on (complex double-float)?
Date: 
Message-ID: <8fs0d8$jtd$1@nnrp1.deja.com>
In article <··············@rtp.ericsson.se>,
  Raymond Toy <···@rtp.ericsson.se> wrote:
>
> Is it possible to have a method specializing on (complex
> double-float)?
>
> The CLHS says the parameter specializer has to be a symbol or (eql
> <stuff>), so, strictly, you can't.
>
> Is there some other way of doing this?
>
> Ray
>

Keep in mind that an implementation might not actually *have* a
distinct representation for (complex double-float). It might store it
internally as (complex t) for example. This means that checking whether
a numer is of type (complex double-float) does not make sense. Rather,
Lisp asks "Could this complex result from *upgrading* (complex double-
float)?". So even if you could use something other than a symbol as a
parameter specializer, the code would not be portable.

--SRS


Sent via Deja.com http://www.deja.com/
Before you buy.
From: Raymond Toy
Subject: Re: Method specializing on (complex double-float)?
Date: 
Message-ID: <4n7lcuqk4k.fsf@rtp.ericsson.se>
>>>>> "SRS" == SRS  <·····@my-deja.com> writes:

    SRS> In article <··············@rtp.ericsson.se>,
    SRS>   Raymond Toy <···@rtp.ericsson.se> wrote:
    >> 
    >> Is it possible to have a method specializing on (complex
    >> double-float)?
    >> 
    >> The CLHS says the parameter specializer has to be a symbol or (eql
    >> <stuff>), so, strictly, you can't.
    >> 
    >> Is there some other way of doing this?
    >> 
    >> Ray
    >> 

    SRS> Keep in mind that an implementation might not actually *have* a
    SRS> distinct representation for (complex double-float). It might store it

Yes, I know that.

    SRS> internally as (complex t) for example. This means that checking whether
    SRS> a numer is of type (complex double-float) does not make sense. Rather,

Of course it makes sense to ask (typep num '(complex double-float).

    SRS> Lisp asks "Could this complex result from *upgrading* (complex double-
    SRS> float)?". So even if you could use something other than a symbol as a
    SRS> parameter specializer, the code would not be portable.

I was asking for a portable solution.  Apparently, there isn't.

So the only portable way is to do something like

(defmethod method ((z complex))
  (let ((zd (coerce z '(complex double-float))))
    (operate-on zd)))

which, for this particular example, isn't such a bad solution.

Ray