SEARCH does not work correctly for some inputs when user-defined sequences are involved

Bug #1153312 reported by Jan Moringen on 2013-03-10
This bug affects 1 person
Affects Status Importance Assigned to Milestone

Bug Description

What I do:
(defclass list-backed-sequence (standard-object sequence)
  ((elements :initarg :elements :type list :accessor %elements)))

(defmethod sequence:make-sequence-like ((sequence list-backed-sequence) length
                                        &rest args &key
                                        initial-element initial-contents)
  (declare (ignore initial-element initial-contents))
  (make-instance 'list-backed-sequence :elements (apply #'sequence:make-sequence-like '() length args)))

(defmethod sequence:length ((sequence list-backed-sequence))
  (length (%elements sequence)))

(defmethod sequence:elt ((sequence list-backed-sequence) index)
  (nth index (%elements sequence)))

(defmethod (setf sequence:elt) (new-value (sequence list-backed-sequence) index)
  (setf (nth index (%elements sequence)) new-value))

(search #(1) (coerce #(1 2 3 2 1) 'list-backed-sequence) :start2 1)

What happens:
0 is returned

What I expected to happen:
4 is returned

$ sbcl --version
SBCL 1.1.5
$ uname -a
Linux ferberit 3.5.0-25-generic #38-Ubuntu SMP Mon Feb 18 23:28:26 UTC 2013 i686 i686 i686 GNU/Linux
$ sbcl --eval '(print *features*)' --quit

Jan Moringen (scymtym) wrote :

The attached patch extends some tests in tests/seq.impure.lisp to user-defined sequences. It also contains a new implementation of SEQUENCE:SEARCH which passes the tests and is slightly faster on the inputs in tests/seq.impure.lisp.

Stas Boukarev (stassats) on 2013-03-10
tags: added: review
Changed in sbcl:
importance: Undecided → Low
status: New → Triaged
Changed in sbcl:
status: Triaged → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers