Changeset 236


Ignore:
Timestamp:
Jan 7, 2004, 3:39:42 PM (21 years ago)
Author:
Gary Byers
Message:

ASSOC variants don't allow NIL in an alist. ASSEQL typechecks CAR/CDR.
MEMEQL uses ENDP, doesn't use %CAR/%CDR in unsafe contexts.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ccl/level-1/l1-utils.lisp

    r85 r236  
    446446
    447447(defun asseql (item list)
    448   (when (not (listp list))(setq list (%kernel-restart $xwrongtype list 'list)))
    449   (locally (declare (list list))
    450     (if (need-use-eql-macro item)
    451       (dolist (pair list)
    452         (if (and pair (eql item (%car pair)))
    453           (return pair)))
    454       (dolist (pair list)       
    455         (when (and pair (eq item (%car pair)))
    456           (return pair))))))
     448  (if (need-use-eql-macro item)
     449    (dolist (pair list)
     450      (if pair
     451        (if (eql item (car pair))
     452          (return pair)
     453          (report-bad-arg pair 'cons))))
     454    (assq pair list)))
    457455
    458456; (assoc-test item list test-fn)
     
    462460(defun assoc-test (item list test-fn)
    463461  (dolist (pair list)
    464     (if (and pair (funcall test-fn item (car pair)))
    465       (return pair))))
     462    (if pair
     463      (if (funcall test-fn item (car pair))
     464        (return pair))
     465      (report-bad-arg pair 'cons))))
    466466
    467467
     
    473473(defun assoc-test-not (item list test-not-fn)
    474474  (dolist (pair list)
    475     (if (and pair (not (funcall test-not-fn item (car pair))))
    476       (return pair))))
     475    (if pair
     476      (if (not (funcall test-not-fn item (car pair)))
     477        (return pair))
     478      (report-bad-arg pair 'cons))))
    477479
    478480(defun assoc (item list &key test test-not key)
     
    488490      (if test
    489491        (dolist (pair list)
    490           (when pair
     492          (if pair
    491493            (if (funcall test item (funcall key (car pair)))
    492               (return pair))))
     494              (return pair))
     495            (report-bad-arg pair 'cons)))
    493496        (dolist (pair list)
    494           (when pair
     497          (if pair
    495498            (unless (funcall test-not item (funcall key (car pair)))
    496               (return pair))))))))
     499              (return pair))
     500            (report-bad-arg pair 'cons)))))))
    497501
    498502
     
    504508;nil or error - supposed to error if not proper list?
    505509(defun memeql (item list)
    506   (when (not (listp list))(setq list (%kernel-restart $xwrongtype list 'list)))
    507510  (if (need-use-eql-macro item)
    508     (do* ((l list (cdr l)))
    509          ((null l))
     511    (do* ((l list (%cdr l)))
     512         ((endp l))
    510513      (when (eql (%car l) item) (return l)))
    511     (do* ((tail list (cdr tail)))
    512          ((null tail))
    513       (if (eq item (%car tail))
    514         (return tail)))))
     514    (memq item list))
     515)
    515516
    516517; (member-test item list test-fn)
     
    538539(defun member-test-not (item list test-not-fn)
    539540  (do* ((l list (cdr l)))
    540        ((null l))
    541     (unless (funcall test-not-fn item (car l)) (return l))))
     541       ((endp l))
     542    (unless (funcall test-not-fn item (%car l)) (return l))))
    542543
    543544(defun member (item list &key test test-not key)
     
    553554      (if test
    554555        (do* ((l list (cdr l)))
    555              ((null l))
     556             ((endp l))
    556557          (if (funcall test item (funcall key (car l)))
    557558              (return l)))
Note: See TracChangeset for help on using the changeset viewer.