没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
试读
581页
这本《Practical Common Lisp》之所以号称Practical,正是因为这本书大量介绍Common Lisp在现实世界中的各种应用方式,算是第一本「入世传教」的Common Lisp著作。《Practical Common Lisp》是目前最畅销的Common Lisp著作,出版至今不过半年,却已经成为Common Lisp使用者人手一本的书,可见这本书的重要性。 本书一开始完整地介绍Common Lisp语言,让读者彻底了解这个语言,最后用超过三分之一的篇幅介绍各种实际应用。本书有相当多应用程序的范例,透过本书的各个范例,你会渐渐体会到,运用Common Lisp写程序是很酷的事。
资源推荐
资源详情
资源评论
Practical
Practical
Practical
Practical Common
Common
Common
Common Lisp
Lisp
Lisp
Lisp
that book is dead sexy — Xach on #lisp
( more blurbs )
This page, and the pages it links to, contain text of the Common Lisp book
Practical Common
Lisp
published by Apress These pages now contain the final text
as
it appears in the book. If you
find errors in these pages, please send email to book@gigamonkeys.com . These pages will remain
online in perpetuity — I hope they will serve
as
a useful introduction to Common Lisp for folks
who are curious about Lisp but maybe not yet curious enough to shell out big bucks for a dead-tree
book and a good Common Lisp tutorial for folks who want to get down to real coding right away.
However, don't let that stop you from buying the printed version available from Apress at your
favorite local or online bookseller. For the complete bookstore browsing experience, you can read
the letter to the reader that appears on the back cover of the treeware edition of the book.
Going to be huge in Japan !
Japanese publisher Ohmsha is publishing a Japanese translation of Practical Common Lisp which
should be avaliable in bookstores July 26, 2008.
English version on its third printing
Amaz on | Powells | Barnes & Noble
Download
Download
Download
Download source
source
source
source code:
code:
code:
code: tar.gz | zip
Now
Now
Now
Now available:
available:
available:
available: Lispbox v0.7 distributions
Spread the word
Like what you've read? Then help spread the word. Recommend this book to your friends. Write a
review on Amaz on. Blog about it. Link to this page from your web site. Whatever. Apress took a
chance, publishing this book when other publishers thought there was no market for a Lisp book.
While it's unlikely that
I'll
get rich off my royalties, we don't have to sell
all
that many copies for
Apress to turn a profit and show the naysayers that Lisp has legs yet.
1 Introduction: Why Lisp?
2 Lather, Rinse, Repeat:
A
Tour of the REPL
3 Practical:
A
Simple Database
4
Syntax and Semantics
5 Functions
6 Variables
7 Macros: Standard Control Constructs
8 Macros: Defining
Your
Own
9
Practical: B uilding a Unit Test Framework
10 Numbers, Characters, and Strings
11 Collections
12 They Called
It
LISP for a Reason: List Processing
13 B eyond Lists: Other Uses for Cons Cells
14
Files and File I/O
15 Practical:
A
Portable Pathname Library
16 Object Reorientation: Generic Functions
17 Object Reorientation: Classes
18
A
Few FORMAT Recipes
19
Beyond Exception Handling: Conditions and Restarts
20 The Special Operators
21 Programming in the Large: Packages and Symbols
22 LOOP for Black Belts
23 Practical:
A
Spam Filter
24
Practical: Parsing Binary Files
25 Practical: An ID3 Parser
26 Practical:
Web
Programming with AllegroServe
27 Practical: An MP3 Database
28 Practical:
A
Shoutcast Server
29
Practical: An MP3 Browser
30 Practical: An HTML Generation Library, the Interpreter
31 Practical: An HTML Generation Library, the Compiler
32 Conclusion: What's Next?
1.
1.
1.
1. Introduction:
Introduction:
Introduction:
Introduction: Why
Why
Why
Why Lisp?
Lisp?
Lisp?
Lisp?
If you think the greatest pleasure in programming comes from getting a lot done with code that
simply and clearly expresses your intention, then programming in Common Lisp is likely to be
about the most fun you can have with a computer. You'll get more do ne, faster, using it than you
would using pretty much any other language.
That's a bold claim. Can I justify it? Not in a just a few pages in this chapter--you're going to have
to learn some Lisp and see for yourself--thus the rest of this book. For now, let me start with some
anecdotal evidence, the story of my own road to Lisp. Then, in the next section,
I'll
explain the
payoff I think you'll get from learning Common Lisp.
I'm one of what must be a fairly small number of second-generation Lisp hackers. My father got
his start in computers writing an operating system in assembly for the machine he used to gather
data for his doctoral dissertation in physics. After running co mputer systems at various physics labs ,
by the 1980s he had left physics altogether and was working at a large pharmaceutical company.
That company had a project under way to develop software to model production processes in its
chemical plants--if you in crease the siz e of this vessel, how does it affect annual production? The
original team, writing in FORTRAN, had burned through half the money and almost
all
the time
allotted to the project with nothing to show for their efforts. This being the 1980s and the middle of
the artificial intelligence (AI) boom, Lisp was in the
air.
So my dad--at that point not a Lisper--
went to Carnegie Mellon University (CMU) to talk to some of the folks working on what was to
become Common Lisp about whether Lisp might be a good language for this project.
The CMU folks showed him some demos of stuff they were working on, and he was convinced. He
in turn convinced his bosses to let his team take over the failing project and do it in Lisp.
A
year
later, and using only what was left of the original budget, hi
s
team delivered a working application
with features that the original team had given
up
any hope of delivering. My dad credits his team's
success to their decision to use Lisp.
Now, that's just one anecdote. And maybe my
dad
is wrong about why they succeeded. Or maybe
Lisp was better only in comparison to other languages of the
day.
These days we have lots of fancy
new languages, many of which have incorporated features from Lis p. Am I really saying Lisp can
offer you the same benefits today
as
it offered my
dad
in the 1980s? Read on.
Despite my father's best efforts, I didn't learn any Lisp in high school. After a college career that
didn't involve much programming in any language, I was seduced by the
Web
and
back into
computers. I worked first in Perl, learning enough to be dangerou
s
while building an online
discussion forum for
Mother Jones
magazine's
Web
site
and
then moving to a
Web
shop, Organic
Online, where I worked on big--for the time--Web sites such
as
the one Nike put
up
during the
1996 Olympics. Later I moved onto Java
as
an early developer at WebLogic, now part of BEA.
After
WebL
ogic, I joined another startup where I was the
lead
programmer on a team building a
transactional messaging system in Java. Along the
way,
my general interest in programming
languages
led
me to explore such mainstream languages
as
C,
C++,
and
Python,
as
w
ell
as
less
well-known ones such
as
Smalltalk, Eiffel,
and
Beta.
So I knew two languages inside
and
out
and
was familiar with another half doz en. Eventually,
however, I realiz ed my interest in programming languages was really rooted in the idea planted by
my father's tales of Lisp--that different languages really are d ifferent,
and
that, despite the formal
Turing equivalence of
all
programming languages, you really can get more done more quickly in
some languages than others
and
have more fun doing it.
Yet,
ironically, I
had
never spent that much
time with Lisp itself. So, I started doing some Lisp hacking in my free time. And whenever I did, it
was exhilarating how quickly I was able to go from idea to working code.
For example, one vacation, having a week
or
so to hack Lisp, I decided to try writing a version of a
program--a system for breeding genetic algorithms to play the game of Go--that I
had
written early
in my career
as
a Java programmer. Even handicapped by my then rudimentary knowledge of
Common Lisp
and
having to look
up
even basic functions, it still felt more productive than it would
have been to rewrite the same program in Java, even with several extra years of Java experience
acquired since writing the first version.
A
similar experiment
led
to the library
I'll
discuss in Chapter 24. Early in my time at WebLogic I
had
written a library, in Java, for taking apart Java class files.
It
worked, but the code was a bit of a
mess
and
hard to modify
or
extend. I
had
tried sev eral times, over the years, to rewrite that library,
thinking that with my ever-improving Java chops
I'd
find some way to do it that didn't bog down in
piles of duplicated code. I never found a
way.
But when I tried to do it in Common Lisp, it took me
onl y two days,
and
I ended
up
not only with a Java class file parser but with a general-purpose
library for taking apart any kind of binary file. You'll see how that library works in Chapter 24
and
use it in Chapter 25 to write a parser for the ID3 tags embe dded in MP3 files.
Why
Why
Why
Why Lisp?
Lisp?
Lisp?
Lisp?
It's hard, in only a few pages of an introductory chapter, to explain why users of a language like it,
and
it's even harder to make the case for why you should invest your time in learning a certain
language. Personal history only gets us so
far.
Perhaps I like Lisp because of some quirk in the way
my brain is wired.
It
could even be genetic, since my
dad
has it too. So before you dive into
learning Lisp, it's reasonable to want to know what the payoff is going to be.
For some languages, the payoff is relatively obvious. For instance, if you want to write low-level
code on Unix, you should learn
C.
Or if you want to write certain kinds of cross-platform
applications, you should learn Java. And any of a number companies still use a lot of C++, so if
you want to get a job at one of them, you should learn C++.
For most languages, however, the payoff isn't so easily categoriz ed; it has to do with subjective
criteria such
as
how it feels to use the language. Perl advocates like to say that Perl "makes easy
things easy
and
hard things possible"
and
revel in the fa ct that,
as
the Perl motto has it, "There's
more than one way to do it."
1
Python's fans, on the other hand, think Python is clean
and
simple
and
think Python code is easier to understand because,
as
their
motto says, "There's only one way to do
it."
So, why Common Lisp? There's no immediately obvious payoff for adopting Common Lisp the
way there is for
C,
Java,
and
C++ (unless, of course, you happen to own a Lisp Machine). The
benefits of using Lisp have much more to do with the experience of using i
t.
I'll
spend the rest of
this book showing you the specific features of Common Lisp
and
how to use them so you can see
for yourself what it's like. For now
I'll
try to give you a sense of Lisp's philosophy.
The nearest thing Common Lisp has to a motto is the koan-like description, "the programmable
programming language." While cryptic, that description gets at the root of the biggest advantage
Common Lisp still has over other languages. More than any other language, Common Lisp follows
the philosophy that what's good for the language's designer is good for the language's users. Thus,
when you're programming in Common Lisp, you almost never find yourself wishing the language
supported some feature that would make your program easier to write, because,
as
you'll see
throughout this book, you can just
add
the feature yourself.
Consequently, a Common Lisp program tends to provide a much clearer mapping between your
ideas about how the program works
and
the code you actually write.
Your
ideas aren't obscured by
boilerplate code
and
endlessly repeated idioms. This makes your code easier to maintain because
you don't have to wade through reams of code every time you need to make a change. Even
systemic changes to a program's behavior can often be achieved with relatively small changes to
the actual code. This also means you'll deve lop code more quickly; there's less code to write,
and
you don't waste time thrashing around trying to find a clean way to express yourself within the
limitations of the language.
2
Common Lisp is also an excellent language for exploratory programming--if you don't know
exactly how your program is going to work when you first sit down to write it, Common Lisp
provides several features to help you develop your code incrementally
and
i nteractively.
For starters, the interactive read-eval-print loop, which
I'll
introduce in the next chapter, lets you
continually interact with your program
as
you develop it. Write a new function. Test it. Change it.
Try
a different approach.
You
never have to stop for a lengthy compilation cycle.
3
Other features that support a flowing, interactive programming style are Lisp's dynamic typing
and
the Common Lisp condition system. Because of the former, you spend less time convincing the
compiler you should be allowed to run your code
and
more time ac tually running it
and
working on
it,
4
and
the latter lets you develop even your error handling code interactively.
Another consequence of being "a programmable programming language" is that Common Lisp, in
addition to incorporating small changes that make particular programs easier to write, can easily
adopt big new ideas about how programming languages should work. F
or
instance, the original
implementation of the Common Lisp Object System (CLOS), Common Lisp's powerful object
system, was
as
a library written in portable Common Lisp. This allowed Lisp programmers to gain
actual experience with the facilities it provid
ed
before it was officially incorporated into the
language.
Whatever new paradigm comes down the pike next, it's extremely likely that Common Lisp will be
able to absorb it without requiring any changes to the core language. For example, a Lisper has
recently written a library, AspectL, that adds support for aspec t-oriented programming (AOP) to
Common Lisp.
5
If AOP turns out to be the next big thing, Common Lisp will be able to support it
without any changes to the base language
and
without extra preprocessors
and
extra compilers.
6
Where
Where
Where
Where It
It
It
It Began
Began
Began
Began
剩余580页未读,继续阅读
eagle_m
- 粉丝: 4
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
前往页