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

Dan Knapp dankna at accela.net
Wed Mar 2 04:13:58 PST 2005


>> People may be left with the impression that Common lisp really should
>> have an extensible abstract protocol for defining SEQUENCE-like 
>> methods
>> on SEQUENCE-like objects.  There is not (and never has been) anything
>> stopping anyone from developing such a library, aside from the fact 
>> that
>> designing something general and usable is hard.
>
> Well, it also winds up not being a basic part of Common Lisp.  It 
> winds up being like the Standard Template Library for C++.  That only 
> took *how* many years before it's existence could actually be assumed? 
>  Fortunately, Common Lisp does not have the same level of baseline 
> incompatibility problems that the C++ compilers had.

   It could actually be pretty small, I think.  Difficult to write, 
mostly because it
isn't clear what the semantics should be, but not large.  So this 
hypothetical
library could easily be included with other projects, as necessary.

   The easiest way would probably be something like:

(defpackage "CL-SEQUENCE"
	(:use "CL")
	(:shadow "CAR" "CDR" "NTH" "AREF" .....))

(defgeneric nth (n seq)
   (:method ((n (integer 0)) (seq t))
       (cl:nth n seq)))

   Then packages wanting these semantics would just use the "CL-SEQUENCE"
package instead of "CL", and everything else would be unaffected.

   Mind you, I haven't even thought about whether it would be a good 
idea.  I'm
just pointing out that CL does make it pretty easy to implement this 
kind of
language extension, since that is after all a lot of what Lisp is 
about.  Being a
formal part of the language is only relevant if optimization is needed 
to make
it usable - and even for that, there are compiler macros.

-- Dan Knapp




More information about the Openmcl-devel mailing list