PDA

View Full Version : Lisp Lists



Mr.Macdonald
December 15th, 2008, 01:38 AM
how do you check if a variable is a list

Tuna-Fish
December 15th, 2008, 01:56 AM
In what lisp?

Mr.Macdonald
December 15th, 2008, 01:59 AM
Common Lisp

wtwood
December 15th, 2008, 03:26 AM
The predicate listp returns t if its argument is the empty list or a cons and nil otherwise:

* (defvar *v2* (list 1))

*V2*
* (defvar *v1* 1)

*V1*
* (listp *v1*)

NIL
* (listp *v2*)

T
* (listp '())

T
*
The first two lines set the variables *v1* to the number 1 and the variable *v2* to a list containing one thing, the number 1. The next two lines show that *v1* is not a list and *v2* is a list. The last line shows that the empty list, written either '() or nil, is a list.