Here is a version of the optimized pairp function that should work for any Lisp (I also get a bug with LispWorks 5.1):
- the declaration is now correct.
- the function works exactly like the original one.
;;; thing: should be anything but a dotted list
(defun pairp (thing)
(declare (optimize (speed 3) (safety 0)))
(and (listp thing) ; proper, dotted or circular list
thing
(let ((thing-cdr (cdr thing)))
(and thing-cdr
(null (cdr thing-cdr)))))) ; if thing is a dotted list: error
Francis
KM 4 > (defun pairp (list)(and (listp list) (eq (length list) 2)))
pairp
KM 5 > (pairp '(1 . 2))
Error: In a call to length of (1 . 2), tail 2 is not a LIST.
This should be what you want:
;;; return T if thing is 2 elements proper list
(defun pairp (thing)
(declare (optimize (speed 3) (safety 0)))
(and (consp thing)
(let ((thing-cdr (cdr thing)))
(and (consp thing-cdr)
(null (cdr thing-cdr))))))
Francis
Le 8/07/2008 18:05, Pete écrivait :