Changeset 286


Ignore:
Timestamp:
Jan 13, 2004, 5:08:01 PM (21 years ago)
Author:
Gary Byers
Message:

ALT-LIST-LENGTH here. LAST allows positive integers. GET-PROPERTIES
uses a TYPE-ERROR to complain about bad plists.

File:
1 edited

Legend:

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

    r85 r286  
    137137                      (%rplacd splice x)) result)))))
    138138
    139 
    140 ; take two args this week
     139(defun alt-list-length (l)
     140  "Detect (and complain about) cirucular lists; allow any atom to
     141terminate the list"
     142  (do* ((n 0 (1+ n))
     143        (fast l)
     144        (slow l))
     145       ((atom fast) n)
     146    (declare (fixnum n))
     147    (setq fast (cdr fast))
     148    (if (logbitp 0 n)
     149      (if (eq (setq slow (cdr slow)) fast)
     150        (%err-disp $XIMPROPERLIST l)))))
     151
    141152
    142153(defun last (list &optional (n 1))
    143   (unless (and (typep n 'fixnum)
    144                (>= (the fixnum n) 0))
    145     (report-bad-arg n '(and fixnum unsigned-byte)))
    146   (locally (declare (fixnum n))
    147     (do* ((checked-list list (cdr checked-list))
    148           (returned-list list)
    149           (index 0 (1+ index)))
    150          ((atom checked-list) returned-list)
    151       (declare (type index index))
    152       (if (>= index n)
    153           (pop returned-list)))))
     154  (if (and (typep n 'fixnum)
     155           (>= (the fixnum n) 0))
     156    (locally (declare (fixnum n))
     157      (do* ((checked-list list (cdr checked-list))
     158            (returned-list list)
     159            (index 0 (1+ index)))
     160           ((atom checked-list) returned-list)
     161        (declare (type index index))
     162        (if (>= index n)
     163          (pop returned-list))))
     164    (if (and (typep n 'bignum)
     165             (> n 0))
     166      (require-type list 'list)
     167      (report-bad-arg  n 'unsigned-byte))))
    154168
    155169
     
    757771      ((null plist) (values nil nil nil))
    758772    (cond ((atom (cdr plist))
    759            (error "~S is a malformed proprty list."
    760                   place))
     773           (report-bad-arg place '(satisfies plistp)))
    761774          ((memq (car plist) indicator-list) ;memq defined in kernel
    762775           (return (values (car plist) (cadr plist) plist))))))
Note: See TracChangeset for help on using the changeset viewer.