Shammer's Philosophy

My private adversaria

Is normal cons? Is dot cons?

There is a case to want to know that the cons is normal cons or dotted cons. In detail, the cons is like ("A" "B") or ("A" . "B"). These cons have a difference how to handle right element. If the cons is like ("A" "B"), the function cadr can access the "B". If the cons is like ("A" . "B"), the function cdr can access the "B". But typep tells just CONS both of them.
So I wrote a small function to judge if the cons is like ("A" "B") or ("A" . "B").

(defun is-dot-cons (c)
  (declare (cons c))  
  (typep (cdr c) 'atom))

Here is an executed result.

? (is-dot-cons '(0 . 0))
T
? (is-dot-cons '(10 20))
NIL
?