LISP: consp or listp ?
When exploring the built-in predicates, Beginning LISPers (in ANSI Common LISP esp.) will often get the following doubt:
Aren't consp & listp the same?
Short answer : No
Why is that?
Well, because not every list is a cons-cell !
What? Can you please explain?
Sure.
Note that NIL
is a list, also denoted by ()
.
But (most importantly!) NIL
is not a cons-cell.
There!
I hope you 'got' the subtle difference between consp
& listp
predicates in LISP.
It should now be clear what the following code snippets produce (Please do try!) :
(consp NIL)
Output: NIL
(=false)
where as,
(listp NIL)
Output: T
(=true)
Note: This pro-tip gives a very compact explanation. For a more detailed write-up, please refer to my detailed article here
Written by Raghu Ugare
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Lisp
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#