Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

II. Lisp is Symmetry > 7. Going Beyond Basic Lists

Chapter 7. Going Beyond Basic Lists

In this chapter, we’ll go beyond basic list concepts. We’ll talk about special kinds of lists, and we’ll write a game that will take list manipulation to a new level.

Exotic Lists

As you learned in Chapter 3, lists in Lisp are built out of cons cells—small data structures that allow you to link together two pieces of data. The right slot in the last cons cell in a list should contain a nil.

By stringing together several cons cells, you can create a list of any length. For instance, this is how we would use cons cells to create a list of the numbers 1, 2, and 3:

(cons 1 (cons 2 (cons 3 nil)))
image with no caption

Since it’s so cumbersome for humans to think of a chain of cons cells as a list, Lisp has a special, simplified syntax for printing out such lists. You can see this for yourself by evaluating a chain of cons cells in the REPL:


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint