Presentation on theme: "Peter Seibel http://www.gigamonkeys.com/book/ Practical Common Lisp Peter Seibel http://www.gigamonkeys.com/book/"— Presentation transcript:
1 Peter Seibel http://www.gigamonkeys.com/book/ Practical Common LispPeter Seibel
2 Outline CHAPTER 1 Introduction: Why Lisp? CHAPTER 2 Lather, Rinse, Repeat: A Tour of the REPLCHAPTER 3 Practical: A Simple DatabaseCHAPTER 4 Syntax and SemanticsCHAPTER 5 FunctionsCHAPTER 6 VariablesCHAPTER 7 Macros: Standard Control ConstructsCHAPTER 8 Macros: Defining Your OwnCHAPTER 9 Practical: Building a Unit Test FrameworkCHAPTER 10 Numbers, Characters, and StringsCHAPTER 11 CollectionsCHAPTER 12 They Called It LISP for a Reason: List ProcessingCHAPTER 13 Beyond Lists: Other Uses for Cons CellsCHAPTER 14 Files and File I/OCHAPTER 15 Practical: A Portable Pathname LibraryCHAPTER 16 Object Reorientation: Generic FunctionsCHAPTER 17 Object Reorientation: ClassesCHAPTER 18 A Few FORMAT Recipes
3 Outline CHAPTER 19 Beyond Exception Handling: Conditions and CHAPTER 20 The Special OperatorsCHAPTER 21 Programming in the Large: Packages and SymbolsCHAPTER 22 LOOP for Black BeltsCHAPTER 23 Practical: A Spam FilterCHAPTER 24 Practical: Parsing Binary FilesCHAPTER 25 Practical: An ID3 ParserCHAPTER 26 Practical: Web Programming with AllegroServeCHAPTER 27 Practical: An MP3 DatabaseCHAPTER 28 Practical: A Shoutcast ServerCHAPTER 29 Practical: An MP3 BrowserCHAPTER 30 Practical: An HTML Generation Library, the InterpreterCHAPTER 31 Practical: An HTML Generation Library, the CompilerCHAPTER 32 Conclusion: What's Next?INDEX
4 GNU CLISP http://clisp.sourceforge.net/ http://www.clisp.org/ 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.
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, andyou'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 siteshttp/SF (sources and win32)Experimenting in the REPLREPL: read-eval-print loopCL-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).
11 “HELLO, WORLD,” LISP STYLE 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, worldNILThe 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.
12 “HELLO, WORLD,” LISP STYLE Examples:CL-USER>(write-line "hello, world")CL-USER>(print "hello, world")CL-USER> (defun hello-world () (format t "hello, world"))HELLO-WORLDDEFUN 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.''
13 “HELLO, WORLD,” LISP STYLE CL-USER> (hello-world)hello, worldNILExamples: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 WORKIf 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.fas0 errors, 0 warnings;; Loading file C:\CLISP\ch1.fas ...;; Loaded file C:\CLISP\ch1.fasTCL-USER>(exit) ;;close the CLISP