From: Daniel J. Yoder
Subject: specialization on subtype
Date: 
Message-ID: <01be50c7$5971d960$932d5d18@thelonious.austin.rr.com>
Is there a way to specialize a generic function on a subtype, such as
(integer 0 *)? I tried using cg::positive-integer (in Allegro CL), but the
interpreter seems to reject these kinds of derived types. TIA,
-D

From: Barry Margolin
Subject: Re: specialization on subtype
Date: 
Message-ID: <tHHu2.2000$oD6.79847@burlma1-snr1.gtei.net>
In article <··························@thelonious.austin.rr.com>,
Daniel J. Yoder <····@Right.Com> wrote:
>Is there a way to specialize a generic function on a subtype, such as
>(integer 0 *)? I tried using cg::positive-integer (in Allegro CL), but the
>interpreter seems to reject these kinds of derived types. TIA,

No.  All classes are types, but not all types are classes.  Consider what
would happen if you did:

(defmethod foo ((self (integer 3 5)))
  (format t "~&3-5~%"))
(defmethod foo ((self (integer 5 7)))
  (format t "~&5-7~%"))

What should be printed for (foo 5)?  Which is the most specific method?

-- 
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Don't bother cc'ing followups to me.
From: Daniel J. Yoder
Subject: Re: specialization on subtype
Date: 
Message-ID: <01be514e$d411fc40$932d5d18@thelonious.austin.rr.com>
Ahhh. Is the requirement for strict precedence the only formal distinction
between classes and types?

If so, why not have a way to explicitly declare precedence of types? 

Just curious. Thanks for the info. Very enlightening.

-D

> >Is there a way to specialize a generic function on a subtype, such as
> >(integer 0 *)? I tried using cg::positive-integer (in Allegro CL), but
the
> >interpreter seems to reject these kinds of derived types. TIA,
> 
> No.  All classes are types, but not all types are classes.  Consider what
> would happen if you did:
> 
> (defmethod foo ((self (integer 3 5)))
>   (format t "~&3-5~%"))
> (defmethod foo ((self (integer 5 7)))
>   (format t "~&5-7~%"))
> 
> What should be printed for (foo 5)?  Which is the most specific method?
From: Barry Margolin
Subject: Re: specialization on subtype
Date: 
Message-ID: <4FMu2.2008$oD6.80849@burlma1-snr1.gtei.net>
In article <··························@thelonious.austin.rr.com>,
Daniel J. Yoder <····@Right.Com> wrote:
>Ahhh. Is the requirement for strict precedence the only formal distinction
>between classes and types?

Not really, although that's part of the criteria that went into defining
the mappings.  Basically, the types that map to classes are a fixed set of
built-in types.  This allows the implementation to look at an object and
efficiently determine what class it is.

If you want extensibility, you're supposed to define new classes.  The
ability to specialize on built-in types is kind of an add-on, just for
convenience, but it's relatively limited in flexibility.

-- 
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Don't bother cc'ing followups to me.