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.

Lisp - consp listp

3 posts · 3853 views

Hello all,

I'm trying to find a way in order to detect the difference between these 2 forms:
(setq MyLst '(word1 word2))
(cons 'word1 'word2)
I've tried to use the consp macro or the listp macro in order to be able to highlight these 2 differents forms. Unfortunatelly, the result is always the same T
I think I missed something.

Re: Lisp - consp listp

Well, it depends on how you are doing things, in general.

They aren't EQUAL, because the first creates 2 cons cells, and the second only 1 (it will print as a dotted list).

Re: Lisp - consp listp

Hmm, you seem to misunderstand, CONSP and LISTP a) aren't macros b) only differ over the handling of NIL (CONSP returns false for NIL, LISTP returns true)

This is because LISTP doesn't check for proper lists, but only whether its argument is a CONS or NIL

If you want to do something special for dotted pairs, then test
(and (cdr x)
     (not (consp (cdr x))))