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:
- ATOM
- (THIS IS AN ATOM)
- (THIS IS AN EXPRESSION)
- ((A B) (C D)) 3 (3)
- (LIST 3)
- (/ (+ 3 1) (- 3 1))
- )(
- ((()))
- (() ())
- ((())
- ())(
- ((ABC
Problem 2-2: Evaluate the following forms:
- (first '(p h w))
- (rest '(b k p h))
- (first '((a b) (c d)))
- (rest '((a b) (c d)))
- (first (rest '((a b) (c d))))
- (rest (first '((a b) (c d))))
- (rest (first (rest '((a b) (c d)))))
- (first (rest (first '((a b) (c d)))))
Problem 2-3: Evaluate the following forms:
- (first (rest (first (rest '((a b) (c d) (e f))))))
- (first (first (rest (rest '((a b) (c d) (e f))))))
- (first (first (rest '(rest ((a b) (c d) (e f))))))
- (first (first '(rest (rest ((a b) (c d) (e f))))))
- (first '(first (rest (rest ((a b) (c d) (e f))))))
- '(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)
- (apple orange pear grapefruit)
- ((apple orange) (pear grapefruit))
- (((apple) (orange) (pear) (grapefruit)))
- (apple (orange) ((pear)) (((grapefruit))))
- ((((apple))) ((orange)) (pear) grapefruit)
- ((((apple) orange) pear) grapefruit)
Hint: First returns a element, while Rest always returns a list.
Problem 2-5: Evaluate the following forms:
- (append '(a b c) '( ))
- (list '(a b c)'( ))
- (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."
Zach Beane said
Steele’s book is especially wonderful. It’s worth reading from cover to cover.
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?
comedy ringtones said
comedy ringtones
Download Cool Ringtone Right This Time: comedy ringtones
Ascerry said
ford modeling agency chicago
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?
mr.search said
Hello
Please prompt where it is possible to buy online viagra
naisioxerloro said
Hi.
Good design, who make it?
Apeliexpiff said
One of the most important roles in this growing industry is played by bookmakers, that deal with the placing of sports bets.
JungleDirector said
Subj.
Anybody have?
I’ts better, if you have XRumer 5.04…
Gimme link
See ya