-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpcl.texi
468 lines (391 loc) · 15.8 KB
/
pcl.texi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
@node Top, Letter, (dir), (dir)
@comment node-name, next, previous, up
@ifinfo
@heading Practical Common Lisp
@noindent
Unofficial Texinfo Format
@copyright{} Peter Seibel
@quotation
“that book is dead sexy” — ‘Xach on #lisp’@*
(@xref{Blurbs}.)
@end quotation
@noindent
This page, and the pages it links to, contain text of the Common Lisp book Practical Common Lisp published by @uref{https://www.apress.com/us/book/9781590592397, 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 @email{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 (@xref{Letter}.) that appears on the back cover of the treeware edition of the book.
@end ifinfo
@menu
* Letter:: Letter to the Reader
* Blurbs:: Blurbs
* Chapter 1:: Introduction: Why Lisp?
* Chapter 2:: Lather, Rinse, Repeat: A Tour of the REPL
* Chapter 3:: Practical: A Simple Database
* Chapter 4:: Syntax and Semantics
* Chapter 5:: Functions
* Chapter 6:: Variables
* Chapter 7:: Macros: Standard Control Constructs
* Chapter 8:: Macros: Defining Your Own
* Chapter 9:: Practical: Building a Unit Test Framework
* Chapter 10:: Numbers, Characters, and Strings
* Chapter 11:: Collections
* Chapter 12:: They Called It LISP for a Reason: List Processing
* Chapter 13:: Beyond Lists: Other Uses for Cons Cells
* Chapter 14:: Files and File I/O
* Chapter 15:: Practical: A Portable Pathname Library
* Chapter 16:: Object Reorientation: Generic Functions
* Chapter 17:: Object Reorientation: Classes
* Chapter 18:: A Few FORMAT Recipes
* Chapter 19:: Beyond Exception Handling: Conditions and Restarts
* Chapter 20:: The Special Operators
* Chapter 21:: Programming in the Large: Packages and Symbols
* Chapter 22:: LOOP for Black Belts
* Chapter 23:: Practical: A Spam Filter
* Chapter 24:: Practical: Parsing Binary Files
* Chapter 25:: Practical: An ID3 Parser
* Chapter 26:: Practical: Web Programming with AllegroServe
* Chapter 27:: Practical: An MP3 Database
* Chapter 28:: Practical: A Shoutcast Server
* Chapter 29:: Practical: An MP3 Browser
* Chapter 30:: Practical: An HTML Generation Library, the Interpreter
* Chapter 31:: Practical: An HTML Generation Library, the Compiler
* Chapter 32:: Conclusion: What's Next?
@detailmenu
--- The Detailed Node Listing ---
1. Introduction: Why Lisp?
* 1-1:: Why Lisp?
* 1-2:: Where It Began
* 1-2-1:: But I learned Lisp Once, And IT Wasn't Like what you're describing
* 1-3:: Who This Book Is For
2. Lather, Rinse, Repeat: A Tour of the REPL
* 2-1:: Choosing a Lisp Implementation
* 2-2:: Getting Up and Running with Lisp in a Box
* 2-3:: Free Your Mind: Interactive Programming
* 2-4:: Experimenting in the REPL
* 2-5:: "Hello, World," Lisp Style
* 2-6:: Saving Your Work
3. Practical: A Simple Database
* 3-1:: CDs and Records
* 3-2:: Filing CDs
* 3-3:: Looking at the Database Contents
* 3-4:: Improving the User Interaction
* 3-5:: Saving and Loading the Database
* 3-6:: Querying the Database
* 3-7:: Updating Existing Records--Another Use for WHERE
* 3-8:: Removing Duplication and Winning Big
* 3-9:: Wrapping Up
4. Syntax and Semantics
* 4-1:: What's with All the Parentheses?
* 4-2:: Breaking Open the Black Box
* 4-3:: S-expressions
* 4-4:: S-expressions As Lisp Forms
* 4-5:: Function Calls
* 4-6:: Special Operators
* 4-7:: Macros
* 4-8:: Truth, Falsehood, and Equality
* 4-9:: Formatting Lisp Code
5. Functions
* 5-1:: Defining New Functions
* 5-2:: Function Parameter Lists
* 5-3:: Optional Parameters
* 5-4:: Rest Parameters
* 5-5:: Keyword Parameters
* 5-6:: Mixing Different Parameter Types
* 5-7:: Function Return Values
* 5-8:: Functions As Data, a.k.a. Higher-Order Functions
* 5-9:: Anonymous Functions
6. Variables
* 6-1:: Variable Basics
* 6-2:: Lexical Variables and Closures
* 6-3:: Dynamic, a.k.a. Special, Variables
* 6-4:: Constants
* 6-5:: Assignment
* 6-6:: Generalized Assignment
* 6-7:: Other Ways to Modify Places
7. Macros: Standard Control Constructs
* 7-1:: WHEN and UNLESS
* 7-2:: COND
* 7-3:: AND, OR, and NOT
* 7-4:: Looping
* 7-5:: DOLIST and DOTIMES
* 7-6:: DO
* 7-7:: The Mighty LOOP
8. Macros: Defining Your Own
* 8-1:: The Story of Mac: A Just-So Story
* 8-2:: Macro Expansion Time vs. Runtime
* 8-3:: DEF MACRO
* 8-4:: A Sample Macro: do-primes
* 8-5:: Macro Parameters
* 8-6:: Generating the Expansion
* 8-7:: Plugging the Leaks
* 8-8:: Macro-Writing Macros
* 8-8-1:: Another classic macro-writing MACRO: ONCE-ONLY
* 8-9:: Beyond Simple Macros
9. Practical: Building a Unit Test Framework
* 9-1:: Two First Tries
* 9-2:: Refactoring
* 9-3:: Fixing the Return Value
* 9-4:: Better Result Reporting
* 9-5:: An Abstraction Emerges
* 9-6:: A Hierarchy of Tests
* 9-7:: Wrapping Up
10. Numbers, Characters, and Strings
* 10-1:: Numbers
* 10-2:: Numeric Literals
* 10-3:: Basic Math
* 10-4:: Numeric Comparisons
* 10-5:: Higher Math
* 10-6:: Characters
* 10-7:: Character Comparisons
* 10-8:: Strings
* 10-9:: String Comparisons
11. Collections
* 11-1:: Vectors
* 11-2:: Subtypes of Vector
* 11-3:: Vectors As Sequences
* 11-4:: Sequence Iterating Functions
* 11-5:: Higher-Order Function Variants
* 11-6:: Whole Sequence Manipulations
* 11-7:: Sorting and Merging
* 11-8:: Subsequence Manipulations
* 11-9:: Sequence Predicates
* 11-10:: Sequence Mapping Functions
* 11-11:: Hash Tables
* 11-12:: Hash Table Iteration
12. They Called It LISP for a Reason: List Processing
* 12-1:: "There Is No List"
* 12-2:: Functional Programming and Lists
* 12-3:: "Destructive" Operations
* 12-4:: Combining Recycling with Shared Structure
* 12-5:: List-Manipulation Functions
* 12-6:: Mapping
* 12-7:: Other Structures
13. Beyond Lists: Other Uses for Cons Cells
* 13-1:: Trees
* 13-2:: Sets
* 13-3:: Lookup Tables: Alists and Plists
* 13-4:: DESTRUCTURING-BIND
14. Files and File I/O
* 14-1:: Reading File Data
* 14-2:: Reading Binary Data
* 14-3:: Bulk Reads
* 14-4:: File Output
* 14-5:: Closing Files
* 14-6:: Filenames
* 14-6-1:: How We Got Here
* 14-7:: How Pathnames Represent Filenames
* 14-8:: Constructing New Pathnames
* 14-9:: Two Representations of Directory Names
* 14-10:: Interacting with the File System
* 14-11:: Other Kinds of I/O
15. Practical: A Portable Pathname Library
* 15-1:: The API
* 15-2:: *FEATURES* and Read-Time Conditionalization
* 15-2-1:: Packaging the Library
* 15-3:: Listing a Directory
* 15-4:: Testing a File's Existence
* 15-5:: Walking a Directory Tree
16. Object Reorientation: Generic Functions
* 16-1:: Generic Functions and Classes
* 16-2:: Generic Functions and Methods
* 16-3:: DEFGENERIC
* 16-4:: DEFMETHOD
* 16-5:: Method Combination
* 16-6:: The Standard Method Combination
* 16-7:: Other Method Combinations
* 16-8:: Multimethods
* 16-8-1:: Multimethods vs. Method Overloading
* 16-9:: To Be Continued . . .
17. Object Reorientation: Classes
* 17-1:: DEFCLASS
* 17-1-1:: What Are "User-Defined Classes"?
* 17-2:: Slot Specifiers
* 17-3:: Object Initialization
* 17-4:: Accessor Functions
* 17-5:: WITH-SLOTS and WITH-ACCESSORS
* 17-6:: Class-Allocated Slots
* 17-7:: Slots and Inheritance
* 17-8:: Multiple Inheritance
* 17-9:: Good Object-Oriented Design
18. A Few FORMAT Recipes
* 18-1:: The FORMAT Function
* 18-2:: FORMAT Directives
* 18-3:: Basic Formatting
* 18-4:: Character and Integer Directives
* 18-5:: Floating-Point Directives
* 18-6:: English-Language Directives
* 18-7:: Conditional Formatting
* 18-8:: Iteration
* 18-9:: Hop, Skip, Jump
* 18-10:: And More . . .
19. Beyond Exception Handling: Conditions and Restarts
* 19-1:: The Lisp Way
* 19-2:: Conditions
* 19-3:: Condition Handlers
* 19-3-1:: JAVA-STYLE EXCEPTON HANDLING
* 19-4:: Restarts
* 19-5:: Providing Multiple Restarts
* 19-6:: Other Uses for Conditions
* 19-6-1:: Writing Robust Software
20. The Special Operators
* 20-1:: Controlling Evaluation
* 20-2:: Manipulating the Lexical Environment
* 20-3:: Local Flow of Control
* 20-4:: Unwinding the Stack
* 20-5:: Multiple Values
* 20-6:: EVAL-WHEN
* 20-7:: Other Special Operators
21. Programming in the Large: Packages and Symbols
* 21-1:: How the Reader Uses Packages
* 21-2:: A Bit of Package and Symbol Vocabulary
* 21-3:: Three Standard Packages
* 21-4:: Defining Your Own Packages
* 21-5:: Packaging Reusable Libraries
* 21-6:: Importing Individual Names
* 21-7:: Packaging Mechanics
* 21-8:: Package Gotchas
22. LOOP for Black Belts
* 22-1:: The Parts of a LOOP
* 22-2:: Iteration Control
* 22-3:: Counting Loops
* 22-4:: Looping Over Collections and Packages
* 22-5:: Equals-Then Iteration
* 22-6:: Local Variables
* 22-7:: Destructuring Variables
* 22-8:: Value Accumulation
* 22-9:: Unconditional Execution
* 22-10:: Conditional Execution
* 22-11:: Setting Up and Tearing Down
* 22-12:: Termination Tests
* 22-13:: Putting It All Together
23. Practical: A Spam Filter
* 23-1:: The Heart of a Spam Filter
* 23-2:: Training the Filter
* 23-3:: Per-Word Statistics
* 23-4:: Combining Probabilities
* 23-5:: Inverse Chi Square
* 23-6:: Training the Filter
* 23-7:: Testing the Filter
* 23-8:: A Couple of Utility Functions
* 23-9:: Analyzing the Results
* 23-10:: What's Next
24. Practical: Parsing Binary Files
* 24-1:: Binary Files
* 24-2:: Binary Format Basics
* 24-3:: Strings in Binary Files
* 24-4:: Composite Structures
* 24-5:: Designing the Macros
* 24-6:: Making the Dream a Reality
* 24-7:: Reading Binary Objects
* 24-8:: Writing Binary Objects
* 24-9:: Adding Inheritance and Tagged Structures
* 24-10:: Keeping Track of Inherited Slots
* 24-11:: Tagged Structures
* 24-12:: Primitive Binary Types
* 24-13:: The Current Object Stack
25. Practical: An ID3 Parser
* 25-1:: Structure of an ID3v2 Tag
* 25-2:: Defining a Package
* 25-3:: Integer Types
* 25-4:: String Types
* 25-5:: ID3 Tag Header
* 25-6:: ID3 Frames
* 25-7:: Detecting Tag Padding
* 25-8:: Supporting Multiple Versions of ID3
* 25-9:: Versioned Frame Base Classes
* 25-10:: Versioned Concrete Frame Classes
* 25-11:: What Frames Do You Actually Need?
* 25-12:: Text Information Frames
* 25-13:: Comment Frames
* 25-14:: Extracting Information from an ID3 Tag
26. Practical: Web Programming with AllegroServe
* 26-1:: A 30-Second Intro to Server-Side Web Programming
* 26-2:: AllegroServe
* 26-3:: Generating Dynamic Content with AllegroServe
* 26-4:: Generating HTML
* 26-5:: HTML Macros
* 26-6:: Query Parameters
* 26-7:: Cookies
* 26-8:: A Small Application Framework
* 26-9:: The Implementation
27. Practical: An MP3 Database
* 27-1:: The Database
* 27-1-1:: The Package
* 27-2:: Defining a Schema
* 27-3:: Inserting Values
* 27-4:: Querying the Database
* 27-5:: Matching Functions
* 27-6:: Getting at the Results
* 27-7:: Other Database Operations
28. Practical: A Shoutcast Server
* 28-1:: The Shoutcast Protocol
* 28-2:: Song Sources
* 28-2-1:: The Package
* 28-3:: Implementing Shoutcast
29. Practical: An MP3 Browser
* 29-1:: Playlists
* 29-1-1:: The Package
* 29-2:: Playlists As Song Sources
* 29-3:: Manipulating the Playlist
* 29-4:: Query Parameter Types
* 29-5:: Boilerplate HTML
* 29-6:: The Browse Page
* 29-7:: The Playlist
* 29-8:: Finding a Playlist
* 29-9:: Running the App
30. Practical: An HTML Generation Library, the Interpreter
* 30-1:: Designing a Domain-Specific Language
* 30-2:: The FOO Language
* 30-3:: Character Escaping
* 30-3-1:: The Package
* 30-4:: Indenting Printer
* 30-5:: HTML Processor Interface
* 30-6:: The Pretty Printer Backend
* 30-6-1:: Using Conditions to Have Your Cake and Eat It Too
* 30-7:: The Basic Evaluation Rule
* 30-8:: What's Next?
31. Practical: An HTML Generation Library, the Compiler
* 31-1:: The Compiler
* 31-2:: FOO Special Operators
* 31-3:: FOO Macros
* 31-4:: The Public API
* 31-5:: The End of the Line
32. Conclusion: What's Next?
* 32-1:: Finding Lisp Libraries
* 32-2:: Interfacing with Other Languages
* 32-3:: Make It Work, Make It Right, Make It Fast
* 32-4:: Delivering Applications
* 32-5:: Where to Go Next
@end detailmenu
@end menu
@include sections/letter.texi
@include sections/blurbs.texi
@include sections/chapter01.texi
@include sections/chapter02.texi
@include sections/chapter03.texi
@include sections/chapter04.texi
@include sections/chapter05.texi
@include sections/chapter06.texi
@include sections/chapter07.texi
@include sections/chapter08.texi
@include sections/chapter09.texi
@include sections/chapter10.texi
@include sections/chapter11.texi
@include sections/chapter12.texi
@include sections/chapter13.texi
@include sections/chapter14.texi
@include sections/chapter15.texi
@include sections/chapter16.texi
@include sections/chapter17.texi
@include sections/chapter18.texi
@include sections/chapter19.texi
@include sections/chapter20.texi
@include sections/chapter21.texi
@include sections/chapter22.texi
@include sections/chapter23.texi
@include sections/chapter24.texi
@include sections/chapter25.texi
@include sections/chapter26.texi
@include sections/chapter27.texi
@include sections/chapter28.texi
@include sections/chapter29.texi
@include sections/chapter30.texi
@include sections/chapter31.texi
@include sections/chapter32.texi