From: ··········@gmail.com
Subject: difference between listp and consp?
Date: 
Message-ID: <1109823250.673696.169150@g14g2000cwa.googlegroups.com>
hi, i have tried and failed, to test out the difference between consp
and listp. I mean practical reasons.. apparently the only difference
recorded in hyperspec is that consp test if a object is cons, and listp
test if an object is a list :|.. they are the same to me for all
practical reason :|

From: Peter Seibel
Subject: Re: difference between listp and consp?
Date: 
Message-ID: <m3acplqs5o.fsf@gigamonkeys.com>
The difference is nothing. Or rather, NIL. That is:

  (consp nil) ==> nil
  (listp nil) ==> t

-Peter

-- 
Peter Seibel                                     ·····@gigamonkeys.com

         Lisp is the red pill. -- John Fraser, comp.lang.lisp
From: Joerg Hoehle
Subject: Re: difference between listp and consp?
Date: 
Message-ID: <ufyzdqd8v.fsf@users.sourceforge.net>
··········@gmail.com writes:
> hi, i have tried and failed, to test out the difference between consp
> and listp.

Too me, there is a difference in style.

I often see code like
  (if (listp foo) (do-something-with (car foo)))
which I rewrite in most cases to
  (if (consp foo) (do-something-with (car foo)))
because I prefer to minimize *superflous* use of (car NIL)
-- I'm not a Schemer, I know when to take advantage of (car NIL)

Mind you, it's not equivalent code. It depends on whether
 (do-something-with NIL) is wished for or not.
Often enough, it's a superfluous call that'll do nothing.

For example, in the Iterate package, I found 85% of listp occurrences
could be turned into consp. Now consp occurs 31 times, and listp 5
times only.

I guess listp is used much more often than the more precise consp
because some people like to think of lists (cf. Kent Pitman's recent
comment on CAR/CDR, LHS/RHS, FIRST/REST).

Here's an example where I very much prefer to use consp over listp:
    (when (and (consp clause) (eq (car clause) 'declare))
      (dolist (spec (cdr clause)) ...))

BTW, for the cycle-counter, consp is likely to compile to a single
machine instruction, whereas listp adds an OR test for the NIL case.

Regards,
	Jorg Hohle
Telekom/T-Systems Technology Center
From: ··········@gmail.com
Subject: Re: difference between listp and consp?
Date: 
Message-ID: <1109850876.741894.155070@z14g2000cwz.googlegroups.com>
hehe, thanks alot for the detailed explanation :D i'll be careful when
i use consp/listp from now on:D thanks alot again !