hraban / cl-containers

Containers Library for Common Lisp
http://common-lisp.net/project/cl-containers/
Other
64 stars 13 forks source link

Iterator dynamic class incorrectly determined #4

Open daewok opened 10 years ago

daewok commented 10 years ago

It seems that when determining the dynamic class of an iterator a nonsensical result is sometimes returned. This can be reproduced by loading cl-containers and evaluating:

(make-iterator '(1 2 3) :circular t :transform #'sqrt)

which returns an iterator of class CIRCULAR-ITERATOR-MIXIN-AND-TRANSFORMING-ITERATOR-MIXIN-AND-LIST-ITERATOR

And then evaluating

(make-iterator '(1 2 3) :circular t)

which also returns an iterator of class CIRCULAR-ITERATOR-MIXIN-AND-TRANSFORMING-ITERATOR-MIXIN-AND-LIST-ITERATOR. Additionally, any attempt to use this iterator immediately errors because the transform function is nil.

This seems to be a result of the success criteria for find-existing-subclass being too weak. It simply finds any class that subclasses all supers, even if that class was defined to include other mixins that aren't in the list of supers.

I actually discovered this while working with the dynamic-classes package, but it's much easier to demonstrate incorrect behavior using cl-container. I'm not sure how to fix this, but if I manage to come up with a way I'll submit a pull request.

fare commented 10 years ago

That's indeed a conceptual bug in cl-containers, which I further contend may be due to cl-containers only having ad hoc polymorphism, not parametric polymorphism, and using the former where the latter should be used instead. lisp-interface-library doesn't have this issue, but has much fewer useful data structures than cl-containers has. I wanted to merge the two, but it was a much bigger endeavor than I actually had time for.

Also, this whole "dynamic mixin" issue is just a (very clever) kluge to make up for lack of runtime class creation and/or a prototype system a la slatelanguage.org. And lisp-interface-library can't really help with that, unless you rewrite it to use sheeple or some such. And then, you need some partial evaluation library or some such to get high performance out of the resulting data structures. Sigh. So much hacking required to get the perfect data structure library, and only one life.

gwkkwg commented 10 years ago

Hi there,

I agree that you've found a bug. If you find a fix, I'd be happy to merge it in. My time constraints are such that it's unlikely that I'll ever get to it. As Faré said, so much work and only one life :-).

On Feb 16, 2014, at 7:39 PM, daewok notifications@github.com wrote:

It seems that when determining the dynamic class of an iterator a nonsensical result is sometimes returned. This can be reproduced by loading cl-containers and evaluating:

(make-iterator '(1 2 3) :circular t :transform #'sqrt) which returns an iterator of class CIRCULAR-ITERATOR-MIXIN-AND-TRANSFORMING-ITERATOR-MIXIN-AND-LIST-ITERATOR

And then evaluating

(make-iterator '(1 2 3) :circular t) which also returns an iterator of class CIRCULAR-ITERATOR-MIXIN-AND-TRANSFORMING-ITERATOR-MIXIN-AND-LIST-ITERATOR. Additionally, any attempt to use this iterator immediately errors because the transform function is nil.

This seems to be a result of the success criteria for find-existing-subclass being too weak. It simply finds any class that subclasses all supers, even if that class was defined to include other mixins that aren't in the list of supers.

I actually discovered this while working with the dynamic-classes package, but it's much easier to demonstrate incorrect behavior using cl-container. I'm not sure how to fix this, but if I manage to come up with a way I'll submit a pull request.

— Reply to this email directly or view it on GitHub.

Gary Warren King, metabang.com Cell: (413) 559 8738 Fax: (206) 338-4052 gwkkwg on Skype * garethsan on AIM * gwking on twitter