Page 1 of 1

differentiate cons & list

Posted: Fri Dec 07, 2012 11:53 am
by dericbytes
I want to know when an item is a cons and when it is a list

Code: Select all

(consp (cons 1 1))
> t

Code: Select all

(listp (cons 1 1))
>t

Code: Select all

(consp (list 1 1))
>t

Code: Select all

(listp (list 1 1))
>t

Code: Select all

(nth 1 (cons 1 1))
> error not a list

Re: differentiate cons & list

Posted: Sat Dec 08, 2012 4:15 am
by Goheeca
What about this:

Code: Select all

(defun true-list-p (list)
  (cond ((null list) t)
        ((consp list) (true-list-p (cdr list)))
        (t nil)))