Page 1 of 1

State of user extensible sequences

Posted: Wed Jun 29, 2011 7:43 pm
by schoppenhauer
As it would come handy in what I am currently programming, I was wondering whether "User-extensible sequences in common Lisp" described in http://citeseerx.ist.psu.edu/viewdoc/do ... 1&type=pdf or something similar has already made its way into some common lisp implementation. Does anybody know this?

Edit:
Ok, just after I posted this I found that SBCL seems to have this extension. But something is not working. When defining

Code: Select all

(defclass my-seq (sequence) ())
I cannot use

Code: Select all

#'make-instance
There is no applicable method for the generic function #<STANDARD-GENERIC-FUNCTION INITIALIZE-INSTANCE (5)>. Why is that? Why do I have to write my own initialize-instance? Usually, this is done automatically.

Re: State of user extensible sequences

Posted: Wed Jun 29, 2011 8:10 pm
by nuntius
Unfortunately, I don't believe this has seen widespread adoption. Try SBCL. There's also a port to ABCL.

I don't have first-hand experience with this protocol. Need to change that...

Re: State of user extensible sequences

Posted: Thu Jun 30, 2011 2:26 pm
by astalla
schoppenhauer wrote:Ok, just after I posted this I found that SBCL seems to have this extension.
In fact Christophe Rhodes, the author of the extensible sequences paper, is an SBCL developer and quite famous Lisper.
schoppenhauer wrote:But something is not working. When defining

Code: Select all

(defclass my-seq (sequence) ())
I cannot use

Code: Select all

#'make-instance
There is no applicable method for the generic function #<STANDARD-GENERIC-FUNCTION INITIALIZE-INSTANCE (5)>. Why is that? Why do I have to write my own initialize-instance? Usually, this is done automatically.
You have to explicitly specify standard-object as a superclass, since it's not a superclass of sequence and the implementation is not allowed to change that. So:

Code: Select all

(defclass my-seq (sequence standard-object) ())
I ported the SBCL implementation of extensible sequences to ABCL. If you're familiar with the Java Collections API, you might want to have a look at how I integrated it with CL sequences in ABCL [1]. Not that it's particularly clever or anything, it's pretty naive, but nevertheless it's an example of the usage of the extensible sequences protocol.

[1] http://trac.common-lisp.net/armedbear/b ... tions.lisp

Re: State of user extensible sequences

Posted: Fri Jul 01, 2011 12:29 am
by schoppenhauer
Thank you. Yes, that works. I wonder how efficient this is, I think I would not have implemented this extension with the object system, but rather with callbacks, for reasons of efficiency, but who cares.

I wonder why other implementations do not adapt this. Having some mechanism of optimizing what #'elt actually does should be necessary anyway, as vectors, non-adjustable arrays and adjustable arrays, and lists should have completely different methods of accessing, so this should be some work, but not too much (I would expect that gray streams had been more work).