Lisp - How can I check if a list is a dotted pair?

A lisp list in "dotted pair notation" looks something like:

(1 . ()).

Since this is homework, I'll let you take this to the logical conclusion. Compare

(LIST 1 2) => (1 . (2 . ()))

with

(CONS 1 2) => (1 . 2).

What is different between these two? How can you tell the difference using predicates?

Remember all proper lisp lists end with the empty list. Ask yourself how do you access the second element of a cons pair? The solution from there ought to be clear.


Because a list always ends with the empty list, while a pair doesn't:

(listp (cdr '(1 2))) => T
(listp (cdr '(1 . 2))) => NIL