Slashdot Mirror


Practical Common Lisp

Frank Buss writes "Common Lisp is an ANSI standard, which defines a general purpose language and library, and is implemented by free and commercial compilers and IDEs; see *hyper-cliki* for more general information about Common Lisp. The book Practical Common Lisp explains the language with many practical examples and is available in full text online, too." Read on for the rest of Buss' review. Practical Common Lisp author Peter Seibel, Gary Cornell (Editor) pages 500 publisher Apress rating 8 reviewer Frank Buss ISBN 1590592395 summary A book for learning and using Common Lisp

Unlike other good books about Lisp, which are focused on a specific domain, like AI (such as Paradigms of Artificial Intelligence Programming ) or basic computer science (for example Structure and Interpretation of Computer Programs for the Lisp-like language Scheme), this book focuses on solving real-world problems in Common Lisp, like web programming, testing etc., after introducing the language by examples in the first chapters. I started with Lisp half an year ago, and it has helped me a lot in learning it. But even if you already know Lisp, this book may be useful for you, because it has a fresh view on the language and the examples in the later chapters are usable in your day-to-day work as a programmer.

The first chapter tells you something about the author (he was a good Java programmer before starting with Lisp) and the history of Lisp and Lisp dialects like Scheme. The next chapters are a tour through all Lisp features, written in easy-to-understand steps, beginning with the installation of a Lisp system and an introduction to the interactive REPL. You don't need any experience in other languages to understand it.

The general concept throughout is to explain a feature first, then show an example of how to use it, with detailed discussion of what the example does and possible pitfalls. A nice example is the APPEND function, which does not copy the last argument:

The reason most list functions are written functionally is it allows them to return results that share cons cells with their arguments. To take a concrete example, the function APPEND takes any number of list arguments and returns a new list containing the elements of all its arguments. For instance:(append (list 1 2) (list 3 4)) ==> (1 2 3 4)

From a functional point of view, APPEND's job is to return the list (1 2 3 4) without modifying any of the cons cells in the lists (1 2) and (3 4). One obvious way to achieve that goal is to create a completely new list consisting of four new cons cells. However, that's more work than is necessary. Instead, APPEND actually makes only two new cons cells to hold the values 1 and 2, linking them together and pointing the CDR of the second cons cell at the head of the last argument, the list (3 4). It then returns the cons cell containing the 1. None of the original cons cells has been modified, and the result is indeed the list (1 2 3 4). The only wrinkle is that the list returned by APPEND shares some cons cells with the list (3 4). The resulting structure looks like this:

In general, APPEND must copy all but its last argument, but it can always return a result that shares structure with the last argument.

In chapter 9, the first larger practical example is developed, a unit testing framework (like JUnit), which is easy to use and to enhance.

Certain Lisp implementation behaviors can be confusing, such as those for for building pathnames. The pathname concept in Lisp is very abstract, leading to different choices in different implementations. This is no problem if you use only one implementation, but chapter 15 develops a portable pathname library, which works on many implementations. By doing this, it shows you how to write portable Lisp code, using different code for different implementations with reader macros.

After an introduction to the Common Lisp Object System (CLOS) and a few practical FORMAT recipes (the printf for Lisp, but more powerful), chapter 19, "Beyond Exception Handling: Conditions and Restarts", is really useful. The exception handling in Lisp (called "condition system") is more general than other exeption systems: In Lisp you can define restarts where you generate an exception and the exeption handler can call these restarts to continue the program. After reading this chapter, you'll never again want to use the restricted version of Java or C++ exception handling.

Chapters 23 to 31 show real world examples: a spam filter, parsing binary files, an ID3 parser, Web programming with AllegroServe, an MP3 database, a Shoutcast server, an MP3 browser and an HTML generation library with interpreter and compiler. If you ever thought that Lisp is an old language, only used for AI research, these chapters prove you wrong: Especially the binary files parser shows you, how you can extend the language with macros for implementing binary file readers, which looks nearly as clear and compact as the plain text binary file description itself. I'm using some of the ideas for a Macromedia Flash SWF file reader/writer I'm currently writing. Take a look at my Web page for my currently published Lisp projects.

The Web programming chapters demonstrates how to use a dynamic approach for generating web pages. You just start a Web server in your Lisp environment; then you can publish static Web pages or define functions, which are called when the page is requested by a browser. The author demonstrates how to define dynamic pages with formulars in Lisp and Lisp HTML generators.

After reading Practical Common Lisp, you will know most of Common Lisp and how to write real-world programs with it. Some special features, like set-dispatch-macro-character, or using one of the non-standard GUI libraries, are not explained, but it is easy to learn the rest of Common Lisp and to use other Lisp libraries, with the knowledge gained from this book.

You can purchase Practical Common Lisp from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page

20 of 617 comments (clear)

  1. I'm sorry, by re-Verse · · Score: 3, Funny

    But since we're practicing it, Isn't that supposed to be lithp

    1. Re:I'm sorry, by b17bmbr · · Score: 3, Funny

      thtop. that'th a thtupid potht. you thould be athamed.

      --
      My problem? I was perfectly gruntled, until some numbnuts came by and dissed me.
  2. Lisp Scheme by superpulpsicle · · Score: 4, Funny

    Lisp is essentially the same as scheme. It's the hardest language to write for IMHO just cause it's out of ordinary.

    There was a story of a hacker stole one of the A.I code from the government. The code turned out to be the last 100 pages of the program. It was all closing paranthesis. That should sum up how nasty the language is.

  3. Re:LISP is amazing. by millennial · · Score: 2, Funny

    Oddly enough, they only taught us the nonsense word names. Well, I suppose 'car' isn't a nonsense word... but in this context it's damn close.

    --
    I am scientifically inaccurate.
  4. Re:This is not a troll, but a query... by Neil+Blender · · Score: 5, Funny

    1. You can post on slashdot when ever the topic comes up.

    2. You can think of yourself as extra cool.

    3. It'll get you laid.

  5. Re:LISP is amazing. by worst_name_ever · · Score: 4, Funny
    I mean, 'car' to grab the first element of a list, and 'cdr' to grab all the others? It can get downright confusing sometimes.

    But it leads to hilarious bumper stickers, such as: "My other car is a cdr"

    --

    In Soviet Rush, today's Tom Sawyer gets high on you.
  6. practical? common? by daraf · · Score: 5, Funny

    (if (or (= lisp practical) (= lisp common)) (monkeys-fly-out 'my-ass) (life-as-normal))

    1. Re:practical? common? by UnknowingFool · · Score: 4, Funny
      (if (or (= lisp practical) (= lisp common)) (monkeys-fly-out 'my-ass) (life-as-normal))

      I don't know what is sadder: the fact that you wrote it, or the fact that I understand what you wrote.

      --
      Well, there's spam egg sausage and spam, that's not got much spam in it.
    2. Re:practical? common? by Anonymous Coward · · Score: 1, Funny

      I think the saddest thing is the way the monkeys-fly-out function takes a symbol to modify its behaviour. That's terrible design. I'd prefer a my-ass object.

  7. Re:LISP is amazing. by stinerman · · Score: 2, Funny
    That doesn't make much sense. I prefer a recent .sig I saw:

    My other car is first.
  8. Re:This is not a troll, but a query... by tool462 · · Score: 2, Funny

    cadr(`yes `no `maybe)

  9. ... programming paradigms by grumpyman · · Score: 4, Funny

    When I think of functional (lisp), my head's twisted and then unwinded. When I think of contraint-based (prolog), my head feels like upside-down. When I think of object-oriented, I think of org-chart. When I think of procedural, I think of spagetti.

  10. Re:LISP is amazing. by nizo · · Score: 1, Funny

    Which leads us to the LISP catch phrase: "Easier to use than assembler".

  11. Re:Practicle Common Lisp???!!! by ari_j · · Score: 2, Funny

    People who can't spell "practical" can't be expected to appreciate the finer things in life.

  12. This article has truly inspired me by Anonymous Coward · · Score: 4, Funny

    To wonder why there isn't a -99 "Suicidally Boring" option when you're moderating...

  13. Common Lisp and Schem are really different. by notany · · Score: 5, Funny

    Comon Lisp and Scheme are as different as programming languages can be.

    Scheme can be said to be ontological attack against Lisp. It looks Lisp but is as far from Lispiness as you can and being still Lisplike.

    Schemer: "Buddha is small, clean, and serious."
    Lispnik: "Buddha is big, has hairy armpits, and laughs."
    -- Nikodemus

    Greenspun's Tenth Rule of Programming:
    "Any sufficiently complicated C or Fortran program contains an ad hoc informally-specified bug-ridden slow implementation of half of Common Lisp."

    Common Lisp people seem to behave in a way that is akin to the Borg: they study the various new things that people do with interest and then find that it was eminently doable in Common Lisp all along and that they can use these new techniques if they think they need them.
    -- Erik Nagggum

    More than anything else, I think it is the ability of Lisp programs to manipulate Lisp expressions that sets Lisp apart. And so no one who has not written a lot of macros is really in a position to compare Lisp to other languages. When I hear people complain about Lisp's parentheses, it sounds to my ears like someone saying:

    "I tried one of those bananas, which you say are so delicious.
    The white part was ok, but the yellow part was very tough and tasted awful."
    -- Paul Graham

    Lisp is about rising above implementation to saying something of lasting
    value. -- Kent Pitman

    Pascal is for building pyramids -- imposing, breathtaking, static structures
    built by armies pushing heavy blocks into place. Lisp is for building
    organisms -- imposing, breathtaking, dynamic structures built by squads
    fitting fluctuating myriads of simpler organisms into place.
    - Alan J. Perils

    Puns are pricey to have in the language becuase they lead to ambiguity
    but they are also a source of great expressional power, so we live
    withthem. People who don't like them should probably seek out Scheme,
    which tends to eschew puns, for better or worse.
    -- Kent M Pitman @ comp.lang.lisp

    Q: How can you tell when you've reached Lisp Enlightenment?
    A: The parentheses disappear.
    LISP has survived for 21 years because it is an approximate local
    optimum in the space of programming languages.
    -- John McCarthy (1980)

    ``Lisp has jokingly been called "the most intelligent way to misuse a
    computer". I think that description is a great compliment because it
    transmits the full flavor of liberation: it has assisted a number of our
    most gifted fellow humans in thinking previously impossible thoughts.''
    -- "The Humble Programmer", E. Dijkstra, CACM, vol. 15, n. 10, 1972

    Lisp is like a ball of mud--you can throw anything you want into it, and
    it's still Lisp".

    Java was, as Gosling says in the first Java white paper,
    designed for average programmers. It's a perfectly
    legitimate goal to design a language for average
    programmers. (Or for that matter for small children, like
    Logo.) But is is also a legitimate, and very different, goal
    to design a language for good programmers.
    -- Paul Graham

    > The continuing holier-than-thou attitude the average lisp programmer...

    There are no average Lisp programmers. We are the Priesthood. Offerings
    of incense or cash will do.

    -- Kenny Tilton at c.l.l

    Dalinian: Lisp. Java. Which one sounds sexier?
    RevAaron: Definitely Lisp. Lisp conjures up images of hippy coders,
    drugs, sex, and rock & roll. Late nights at Berkeley, coding in Lisp
    fueled by LSD. Java evokes a vision of a stereotypical nerd, with no
    life or social skills.

    In the Algol family, parentehses
    signal pain. In the Lisp family, they signal comfort. Since most people are
    highly emotional believers, even programmers, it is very hard for them to
    relinquish their beliefs in their associations of parentheses with pain and
    suffering. This has nothing to do with aesthetics, design rationales, ease
    of u

    --
    Dyslexics have more fnu.
  14. Lisp might be good but.. by glogic · · Score: 2, Funny

    It's a pity, but lets face it: Lisp could never be adpoted for widespread use - there's only a finite number of parenthesis in the universe.

  15. Re:This is not a troll, but a query... by Anonymous Coward · · Score: 2, Funny

    That kind of smug comment is more likely to put people off LISP. I mean, yes Eric, I'm sure fetchmail is a lot better for the fact that you once dabbled in LISP, but don't go all Godel Escher Bach on us.

  16. Re:Tcl/Tk RULES!!! by js7a · · Score: 3, Funny
    Delayed compilation is a feature!

    Which would you rather have, a syntax error where indicating the code is faulty, or a silent semantics error?

    Although (ahem) uh, the possibility of the former doesn't preclude the latter, but, uh, please observe the authoratative manner in which I wave my hands!

  17. Re:My first exposure to list ( and a mirror of boo by omnirealm · · Score: 5, Funny

    Whenever I think of Lisp, I'm transported back in time to 1975 where I'm trying (unsuccessfully) to learn this as my 2nd programming language after Fortran IV (on a DECsystem-10, no less).

    I've heard it said that someone just learning how to program can pick up Lisp in a day. If you happen to already know Fortran, it will take two days.

    --
    An unjust law is no law at all. - St. Augustine