Ignore:
Timestamp:
03/03/10 21:05:41 (11 years ago)
Author:
astalla
Message:

Support for user-extensible sequences, adapted from SBCL.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/find.lisp

    r11391 r12516  
    3131
    3232(in-package #:system)
     33
     34(require "EXTENSIBLE-SEQUENCES-BASE")
    3335
    3436;;; From CMUCL.
     
    143145
    144146
    145 (defun position (item sequence &key from-end (test #'eql) test-not (start 0)
    146                       end key)
    147   (if (listp sequence)
    148       (list-position* item sequence from-end test test-not start end key)
    149       (vector-position* item sequence from-end test test-not start end key)))
    150 
     147(defun position (item sequence &rest args &key from-end (test #'eql) test-not
     148     (start 0) end key)
     149  (sequence::seq-dispatch sequence
     150    (list-position* item sequence from-end test test-not start end key)
     151    (vector-position* item sequence from-end test test-not start end key)
     152    (apply #'sequence:position item sequence args)))
    151153
    152154(defun list-position* (item sequence from-end test test-not start end key)
     
    168170  `(list-locater-if ,test ,sequence :position))
    169171
    170 (defun position-if (test sequence &key from-end (start 0) key end)
    171   (declare (type fixnum start))
    172   (let ((end (or end (length sequence))))
    173     (declare (type fixnum end))
    174     (if (listp sequence)
    175         (list-position-if test sequence)
    176         (vector-position-if test sequence))))
     172(defun position-if (test sequence &rest args &key from-end (start 0) key end)
     173  (declare (type fixnum start))
     174  (let ((end (or end (length sequence))))
     175    (declare (type fixnum end))
     176    (sequence::seq-dispatch sequence
     177      (list-position-if test sequence)
     178      (vector-position-if test sequence)
     179      (apply #'sequence:position-if test sequence args))))
    177180
    178181(defmacro vector-position-if-not (test sequence)
     
    182185  `(list-locater-if-not ,test ,sequence :position))
    183186
    184 (defun position-if-not (test sequence &key from-end (start 0) key end)
    185   (declare (type fixnum start))
    186   (let ((end (or end (length sequence))))
    187     (declare (type fixnum end))
    188     (if (listp sequence)
    189         (list-position-if-not test sequence)
    190         (vector-position-if-not test sequence))))
     187(defun position-if-not (test sequence &rest args &key from-end (start 0) key end)
     188  (declare (type fixnum start))
     189  (let ((end (or end (length sequence))))
     190    (declare (type fixnum end))
     191    (sequence::seq-dispatch sequence
     192      (list-position-if-not test sequence)
     193      (vector-position-if-not test sequence)
     194      (apply #'sequence:position-if-not test sequence args))))
    191195
    192196(defmacro vector-find (item sequence)
     
    208212  (vector-find item sequence))
    209213
    210 (defun find (item sequence &key from-end (test #'eql) test-not (start 0)
    211                   end key)
     214(defun find (item sequence &rest args &key from-end (test #'eql) test-not
     215       (start 0) end key)
    212216  (let ((end (check-sequence-bounds sequence start end)))
    213     (if (listp sequence)
    214         (list-find* item sequence from-end test test-not start end key)
    215         (vector-find* item sequence from-end test test-not start end key))))
     217    (sequence::seq-dispatch sequence
     218      (list-find* item sequence from-end test test-not start end key)
     219      (vector-find* item sequence from-end test test-not start end key)
     220      (apply #'sequence:find item sequence args))))
    216221
    217222(defmacro vector-find-if (test sequence)
     
    221226  `(list-locater-if ,test ,sequence :element))
    222227
    223 (defun find-if (test sequence &key from-end (start 0) end key)
    224   (let ((end (or end (length sequence))))
    225     (declare (type fixnum end))
    226     (if (listp sequence)
    227         (list-find-if test sequence)
    228         (vector-find-if test sequence))))
     228(defun find-if (test sequence &rest args &key from-end (start 0) end key)
     229  (let ((end (or end (length sequence))))
     230    (declare (type fixnum end))
     231    (sequence::seq-dispatch sequence
     232      (list-find-if test sequence)
     233      (vector-find-if test sequence)
     234      (apply #'sequence:find-if test sequence args))))
    229235
    230236(defmacro vector-find-if-not (test sequence)
     
    234240  `(list-locater-if-not ,test ,sequence :element))
    235241
    236 (defun find-if-not (test sequence &key from-end (start 0) end key)
    237   (let ((end (or end (length sequence))))
    238     (declare (type fixnum end))
    239     (if (listp sequence)
    240         (list-find-if-not test sequence)
    241         (vector-find-if-not test sequence))))
     242(defun find-if-not (test sequence &rest args &key from-end (start 0) end key)
     243  (let ((end (or end (length sequence))))
     244    (declare (type fixnum end))
     245    (sequence::seq-dispatch sequence
     246      (list-find-if-not test sequence)
     247      (vector-find-if-not test sequence)
     248      (apply #'sequence:find-if-not test sequence args))))
Note: See TracChangeset for help on using the changeset viewer.