=================[ Readings ]================= Please read Chapter 2 of the free book "On Lisp", http://www.paulgraham.com/onlisp.html ---pay special attention to 2.5 "Scope" and 2.6 "Closures". Try all examples at the command line in GCL or SBCL. Try the scopes examples in Emacs, to see how they behave under Emacs' default _dynamic scoping_. Read Chapter 3 of "On Lisp". Section 3.1 explains the advantages of the functional design by first showing a poor way to reverse a lisp (Fig, 3.1) and then the native functional LISP way (Fig. 3.2). It goes on to discuss _destructive_ implementations and their dangers, and gives a list of destructive functions. Chapters 4 and 5 give you examples of LISP functional style and design. With functions in Sec. 4.6 and 4.7, you can write programs that interact with text inputs and outputs. Sec. 5.3 describes a very important performance mechanism that languages like C/C++ and Java have to implement with complex libraries; in Common Lisp, it's a standard part of the language. Finally, 5.5 and 5.6 discuss efficient recursing over lists and trees. Chapter 7 covers macros. For a short intro, see http://cl-cookbook.sourceforge.net/macros.html Macros allow a LISP programmer to essentially re-define the language and programming style; as a downside, macros can be tricky to debug. Object-oriented programming in Common Lisp relies heavily on macros: declaring a struct (with the defstruct macro) automatically creates macros for constructing its instances, accessing its members, making shallow copies of it, and the like. The defclass macro goes further by letting you specify inheritance of classes. See http://cl-cookbook.sourceforge.net/clos-tutorial/ for more details. =================[ Examples ]================= In class, we saw some effects of destructive operations, including a "looped" list created with nconc, which caused the Print part of REPL to loop forever when printing nconc's result. See destructive-log.txt Destructive operations: destructive-log.txt Lexical vs dynamic scoping: closures-log.txt (GCL log) vs emacs-dynamic-and-static-bindings.txt (Emacs buffer in lisp-interaction-mode) (See also: emacs-dynamic-and-static-bindings-more.txt) =================[ Packages ]================= Packages are a necessity in modern languages. To compete, a language must have many libraries. These libraries use many function names, and these names might collide when the libraries are loaded together, resulting in an unpredictable mess. This problem is solved by separating "name spaces" for libraries, which is served by packages (also called modules in some languages like Perl or Ruby). Packages class log: packages-log.txt I suggest using SBCL to explore packages, because SBCL supports the very convenient Quickload utility (see using-lisp-libraries.txt). Shorter: http://www.flownet.com/gat/packages.pdf More comprehensive, but a bit long-winded: https://www-fourier.ujf-grenoble.fr/~sergerar/Papers/Packaging.pdf You may skip the "mathematical" parts that may seem unclear: the examples are clear enough by themselves. Sections 7 & 9 discuss the strange situation we saw in class when a typed, unbound symbol blocked loading a package---which can only be resolved by un-interning that accidentally created "empty" symbol.