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

I. Lisp is Power > 2. Creating Your First Lisp Program

Chapter 2. Creating Your First Lisp Program

Now that we’ve discussed some of the philosophy of Lisp and have a running CLISP environment, we’re ready to write some actual Lisp code in the form of a simple game.

The Guess-My-Number Game

This first game we’ll write is pretty much the simplest game imaginable. It’s the classic guess-my-number game.

In this game, you pick a number from 1 to 100, and the computer has to guess it.

The following shows what game play might look like if you pick the number 23. The computer starts by guessing 50, and with each successive guess, you enter (smaller) or (bigger) until the computer guesses your number.

> (guess-my-number)
50
> (smaller)
25
> (smaller)
12
> (bigger)
18
> (bigger)
21
> (bigger)
23

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

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

  

Start a Free Trial


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