Function: PROPER-LIST-P

Documentation

Tests whether OBJECT is properlist. A proper list is a non circular cons chain whose last cdr is eq to NIL.

Source

(defun proper-list-p (object)
  "Tests whether OBJECT is properlist.

A proper list is a non circular cons chain whose last cdr is eq
to NIL."
  (or
   (null object)
   (and (consp object)
	;; check if the last cdr of object is null. deal with
	;; circular lists.
	(loop 
	 for turtoise = object then (cdr turtoise)
	 for hare = (cdr object) then (cddr hare)
	 ;; we need to agressivly check hare's cdr so that the call to
	 ;; cddr doesn't signal an error
	 when (eq turtoise hare) return nil
	 when (null turtoise) return t
	 when (null hare) return t
	 when (not (consp hare)) return nil
	 when (null (cdr hare)) return t
	 when (not (consp (cdr hare))) return nil
	 when (null (cddr hare)) return t
	 when (not (consp (cddr hare))) return nil))))
Source Context