Learning Lisp

The Road To Lisp

Use the Library

Posted by j1p on April 24, 2006

Instead of just using online resources like Peter Seibel's Practical Common Lisp [1], I headed down to my University's Library and took out 3 books on Common Lisp. I was originally looking to get a copy of Paul Graham's ANSI Common Lisp[2], but they didn't have it.

So instead I picked up Guy L. Steele's Common Lisp: The Language[3], Winston and Horn's Lisp[4], and Andreas Paepcke's Object-Oriented Programming: The CLOS Perspective[5]. These books may be a bit outdated, but should be good for getting my feet wet with Common Lisp. So far I've only read through Lisp's 1st chapter, and half of the second chapter. The first chapter involved no code, only explanations of lists, uses of Lisp in a real-world environment, why to learn Lisp(especially Common Lisp), and debunked a few myths about Lisp. Nothing I haven't read elsewhere.

The second chapter finally got into real code. It introduced primitives, procedures provided by the Lisp implementation, like arithmitic operators, cons, list, append, first(car), rest(cdr), and setf. Further along in the chapter it goes into push, nthcdr, butlast, last, length, reverse, ASSOC, round, exp, expt, and so on.

For anyone also learning I'll provide the sample problems I've come across so far:

Problem 2-1: Identify if the following are atoms, lists, or neither:

  1. ATOM
  4. ((A B) (C D)) 3 (3)
  5. (LIST 3)
  6. (/ (+ 3 1) (- 3 1))
  7. )(
  8. ((()))
  9. (() ())
  10. ((())
  11. ())(
  12. ((ABC

Problem 2-2: Evaluate the following forms:

  1. (first '(p h w))
  2. (rest '(b k p h))
  3. (first '((a b) (c d)))
  4. (rest '((a b) (c d)))
  5. (first (rest '((a b) (c d))))
  6. (rest (first '((a b) (c d))))
  7. (rest (first (rest '((a b) (c d)))))
  8. (first (rest (first '((a b) (c d)))))

Problem 2-3: Evaluate the following forms:

  1. (first (rest (first (rest '((a b) (c d) (e f))))))
  2. (first (first (rest (rest '((a b) (c d) (e f))))))
  3. (first (first (rest '(rest ((a b) (c d) (e f))))))
  4. (first (first '(rest (rest ((a b) (c d) (e f))))))
  5. (first '(first (rest (rest ((a b) (c d) (e f))))))
  6. '(first (first (rest (rest ((a b) (c d) (e f))))))

Problem 2-4: Write a sequence of first's and rest's that will return the symbol PEAR out of the following expressions. (not the list containing only the atom PEAR, (PEAR), but only the symbol PEAR, PEAR)

  1. (apple orange pear grapefruit)
  2. ((apple orange) (pear grapefruit))
  3. (((apple) (orange) (pear) (grapefruit)))
  4. (apple (orange) ((pear)) (((grapefruit))))
  5. ((((apple))) ((orange)) (pear) grapefruit)
  6. ((((apple) orange) pear) grapefruit)

Hint: First returns a element, while Rest always returns a list.

Problem 2-5: Evaluate the following forms:

  1. (append '(a b c) '( ))
  2. (list '(a b c)'( ))
  3. (cons '(a b c) '( ))

Problem 2-6: Evaluate the following forms in the order given

  • (setf tools (list 'hammer 'screwdriver))
  • (cons 'pliers tools)
  • tools
  • (setf tools (cons 'pliers tools))
  • tools
  • (append '(saw wrench) tools)
  • tools
  • (setf tools (append '(saw wrench) tools))
  • tools

Problem 2-7: Evaluate the following form:

  • (cons (first nil) (rest nil))

I had some trouble on some parts of 2-4, where my sequences would result in the list containing the symbol pear, (PEAR), but that's easily solved by throwing another first on the front of the sequence.

As I continue reading I'll try to keep putting in the example problems, as long as they don't get too involved, and the answers will be in the next post.

One of the problems, well, maybe not so much a problem, but a point of conflict I have run into is which implementation of Common Lisp I should use. Currently, I am running Ubuntu Linux, so I have lots of options to choose from: SBCL, CMUCL, CLISP, Allegro Personal 7.0, and more. Perhaps my next post will deal with the differences between different implementations, in the eyes of a "newbie."


10 Responses to “Use the Library”

  1. Zach Beane said

    Steele’s book is especially wonderful. It’s worth reading from cover to cover.

  2. j1p said

    Yes, a few of the reviews I read had very high praises for Steele’s book. Unfortunately, I only have until early May to read through all these books, as I have to return them before I go back home for summer break. And weighing in at over 1000 pages, Steele’s book seems like a low priority with upcoming final exams and other commitments.

    I am pretty sure the local university library at home has copies of Paul Graham’s ANSI Common Lisp as well as the books I already checked out and a few others.

    Also, thanks a lot for commenting on my blog, with only one day under my belt, and a comment from someone like you(same xach as the one with the quote on the PCL site, i assume), it has made me very encouraged to post more and share my learning experience. May I ask however, how you found it?

  3. comedy ringtones

    Download Cool Ringtone Right This Time: comedy ringtones

  4. Ascerry said

    ford modeling agency chicago

  5. alexrttfd said

    I been searching and searching trying to find the best video game copying software out their. out of months of testing i found one that stood wayy above the rest check out this new

    [url=http://www.gamecopy.mzian.com] game copy pro[/url]

    software and let me know what you think?

  6. mr.search said

    Please prompt where it is possible to buy online viagra

  7. naisioxerloro said

    Good design, who make it?

  8. One of the most important roles in this growing industry is played by bookmakers, that deal with the placing of sports bets.

  9. Subj.
    Anybody have?

    I’ts better, if you have XRumer 5.04…
    Gimme link

    See ya

  10. First off I want to say terrific blog! I had a quick question which
    I’d like to ask if you don’t mind. I was interested to know
    how you center yourself and clear your thoughts prior to writing.
    I’ve had trouble clearing my thoughts in getting my ideas out. I truly do enjoy writing however it just seems like the first 10 to 15 minutes are generally lost just trying to figure out how to begin. Any recommendations or tips? Kudos!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: