Presentation is loading. Please wait.

Presentation is loading. Please wait.

Peter Seibel Practical Common Lisp Peter Seibel

Similar presentations

Presentation on theme: "Peter Seibel Practical Common Lisp Peter Seibel"— Presentation transcript:

1 Peter Seibel
Practical Common Lisp Peter Seibel

2 Outline 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

3 Outline CHAPTER 19 Beyond Exception Handling: Conditions and
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? INDEX

Common Lisp is a high-level, general-purpose, object-oriented, dynamic, functional programming language. CLISP is a Common Lisp implementation by Bruno Haible, then of Karlsruhe University, and Michael Stoll, then of Munich University, both in Germany. CLISP implements the language described in the ANSI Common Lisp standard with many extensions.

5 Chapter 1 Introduction: Why Lisp

6 Why Lisp? Common Lisp is the programmable programming language.
Common Lisp follows the philosophy that what's good for the language's designer is good for the language's users. 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. You will develop code more quickly. There's less code to write. You do not waste time thrashing around trying to find a clean way to express yourself within the limitations of the language. Common Lisp is an excellent language for exploratory(探究) programming. Common Lisp provides several features to help you develop your code incrementally and interactively.

7 Where it Began? LISP: LISt Processing
Common Lisp is the modern descendant of the Lisp language first conceived by John McCarthy in 1956. Who this book is for ? This book is for you if you're curious about Common Lisp. After you finish this book, you'll be familiar with all the most important features of the language and how they fit together, you'll have used Common Lisp to write several nontrivial programs, and you'll be well prepared to continue exploring the language on your own. While everyone's road to Lisp is different, I hope this book will help smooth the way for you.

8 Chapter 2 Lather, Rinse, Repeat: A Tour of the REPL

9 Install Common Lisp Download GNU Clisp and install it
Our official distribution sites http/SF (sources and win32) Experimenting in the REPL REPL: read-eval-print loop CL-USER> This is the Lisp prompt (提示符號). Lisp reads Lisp expressions, evaluates them according to the rules of Lisp, and prints the result. Then it does it again with the next expression you type. That endless cycle of reading, evaluating, and printing is why it's called the read-eval-print loop (REPL).


CL-USER> "hello, world" "hello, world" Lisp reads the double-quoted string and instantiates a string object in memory that, when evaluated, evaluates to itself and is then printed in the same literal syntax. CL-USER> (format t "hello, world") hello, world NIL The FORMAT function takes a variable number of arguments, but the only two required arguments are the place to send the output and a string. The first argument to FORMAT should be the symbol T when we want to write to the display. The second argument must be a string, called the format control string.

Examples: CL-USER>(write-line "hello, world") CL-USER>(print "hello, world") CL-USER> (defun hello-world () (format t "hello, world")) HELLO-WORLD DEFUN is a special kind of function, called a macro function. DEFUN is used to define other functions. The first input to DEFUN is the name of the function being defined. The second input is the argument list: It specifies the names the function will use to refer to its arguments. The remaining inputs to DEFUN define the body of the function: what goes on ''inside the box.''

CL-USER> (hello-world) hello, world NIL Examples: CL-USER>(defun average (x y) (/ (+ x y) 2.0)) CL-USER>(average 4 6) CL-USER>(defun square (n) (* n n)) CL-USER>(square 6)

14 SAVING YOUR WORK If you exit Lisp and restart, the function definition will be gone. Having written such a fine function, you'll want to save your work. Loading a text file: CL-USER>(load "C:/CLISP/filename.lisp") The output T means everything loaded correctly. CL-USER>(load (compile-file "ch1.lisp") A way to load a file's worth of definitions is to compile the file first with COMPILE-FILE and then LOAD the resulting compiled file, called a FASL file. ;; Compiling file C:\CLISP\ch1.lisp ... ;; Wrote file C:\CLISP\ch1.fas 0 errors, 0 warnings ;; Loading file C:\CLISP\ch1.fas ... ;; Loaded file C:\CLISP\ch1.fas T CL-USER>(exit) ;;close the CLISP

Download ppt "Peter Seibel Practical Common Lisp Peter Seibel"

Similar presentations

Ads by Google