This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

differentiate cons & list

2 posts · 6325 views

I want to know when an item is a cons and when it is a list
(consp (cons 1 1))
> t
(listp (cons 1 1))
>t
(consp (list 1 1))
>t
(listp (list 1 1))
>t
(nth 1 (cons 1 1))
> error not a list

Re: differentiate cons & list

What about this:
(defun true-list-p (list)
  (cond ((null list) t)
        ((consp list) (true-list-p (cdr list)))
        (t nil)))
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.