tags:

views:

120

answers:

3

Hi! Allknowing that in lisp list must contain nil, but expression like

(print (cons 1 (cons 3 2)))

dont throw any errors and prints

(1 3 . 2)

Is it correct?

I use GNU Clisp.

Help me please

+1  A: 

When you iterate over a list you know you reached the end when you hit nil. What you have is a list with a car and a point pair.

thelost
+8  A: 

In Lisp, a proper list ends with NIL, but you also have improper lists. One kind of improper list is a list where the last cons cell has an atom other than NIL in its CDR. (1 3 . 2) is exactly such an improper list.

You can even have improper lists where it doesn't have a last cell at all. CARs and CDRs are basically just pointers, so you can have circular lists!

In Common Lisp (which is the language CLISP implements), many standard functions won't work with improper lists as arguments.

Pillsy
+5  A: 

What you have is a dotted list, which is a kind of improper list.

A chain of CONS cells where the last CDR is NIL is a proper list.

Chris Johnsen