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

4. Making Decisions with Conditions > Comparing Stuff: eq, equal, and More

Comparing Stuff: eq, equal, and More

There’s a lot of beautiful symmetry in Lisp. One part of Lisp that isn’t so beautiful, though, involves the commands for comparing things.

If you want to compare two values in Lisp to find out if they are “the same,” you will find a bewildering assortment of different functions that purport to accomplish this. Of these, equal, eql, eq, =, string-equal, and equalp are the most commonly used. A Lisper must understand the subtleties of these functions intimately in order to know how to compare values correctly.

image with no caption

Before we start dissecting this madness, let me give you Conrad’s Rule of Thumb for Comparing Stuff. Follow this rule, and though you may not be writing the world’s cleanest Lisp code, you will probably be able to post some samples to a newsgroup without more seasoned Lispers running you out of town with torches and pitchforks.


  

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