[Openmcl-devel] Applying sequence functions to a new type

Andrew P. Lentvorski, Jr. bsder at mail.allcaps.org
Tue Mar 1 12:26:40 PST 2005

On Mar 1, 2005, at 4:52 AM, Gary Byers wrote:

> On Mon, 28 Feb 2005, Andrew P. Lentvorski, Jr. wrote:
>> This is probably a really stupid question, but how do I define the
>> sequence functions so that they apply to a new class?
> You basically can't reliably subclass BUILT-IN-CLASSes like SEQUENCE
> (or FLOAT or FIXNUM) in CLOS.
> The standard sequence functions are not necessarily GENERIC-FUNCTIONs
> (they aren't in OpenMCL or in any other implementation I'm aware of),
> so you can't extend their behavior by adding methods on them.

Hrm.  Well, this seems like a really nasty limitation.  Is there a 
reason that they are not GENERIC-FUNCTIONS other than accident of 
history?  Especially since when I dig through the source 
implementations of some of these functions, they spend an awful lot of 
code working out exactly what type they just got passed.  It would seem 
like letting the GENERIC-FUNCTION machinery do those checks would save 
a lot of code.  I'm sure I'm missing something obvious though 
(something stupid like CLOS isn't available when those functions are 
needed or something).

Well, given that I can't do what I want, let's change the question.

Given that the ANSI defined sequence functions cannot be used for 
generic data structures, what is the alternative?  ie. If I want to add 
a red-black tree to my system, how should I define the interface such 
that other lispers know what I am doing.

Most modern languages have agreed upon protocols for operating *any* 
sequence type, including those defined by a user.  What are the 
conventions for lisp?

Alternatively, can I somehow define a user sequence function which is a 
GENERIC-FUNCTION and then call the original function when the input is 
not my user data structure?


More information about the Openmcl-devel mailing list