Practical Common Lisp by Peter Seibel
Date: May 10, 2006
Overview
- Good material with mediocre presentation. Seibel seems to hint obliquely at his three major points:
- Lisp gives a higher level view of an implementation than Java et al.
- Lisp constructs can be made to work in other languages, but verbosely.
- The key tool is Macros, which allows programmers to define new syntax to better express the problem.
Details
These are my mostly raw notes from watching the hour long video.
Peter Seibel
- Pronounced “Sigh-bull”
- Practical Common Lisp
- 500 pages long
- Winner of Jolt Award
- Aimed at an expert non-LISP programmer
- Worked at Kenamea, BEA, Organic Online
- Second generation LISP programmer
Ideas from Peter Naur’s “Programming as Theory Building”
- View that ‘theory’ is the essence of a program
- Can only get theory from code without work equivalent to writing it
- Programming languages allow us to write more concisely
Views from Patterns
- Software patterns for people writing software
- Building patterns make some rooms more usable
- Alexander looked for a generative language
- Patterns generate forces; a good language could make closure
- Software patterns are for a particular language sets; others do it automatically.
What’s Natural
- Language wars are often fought based on what’s natural
- What’s natural is often confused with what was learned
- Infix notation is hard to learn, but is ‘natural’ because we learned
Sapir-Whorf hypothesis
- By Edward Sapir and Benjamin Whorf in 1920’s
- Suggests the thoughts we think are largely determined by the language we speak
- Sometimes called Linguistic Determinism
- Strong Linguistic Determinism is that you can’t think what you can’t say
- Weak Linguistic Determinism is that what you can say influences what you think
- Strong LingDet undermined by fact we can translate human languages
- Weak LingDet supported by colors being easier to remember when named
- Turning Completeness destroys Strong LingDet for programming languages
Paul Grahm
- “Beating the Averages” by Paul Grahm
- The ‘Blub’ paradox of the intermediate powerful programming language
- Looking at less powerful languages shows what they lack from Blub
- Looking at more powerful languages looks like Blub plus unknowable gunk
- If you could think in most powerful language possible, could work in any.
Quotes
- “Beware of the Turning Tarpit” by Alan Perlis
- “LISP isn’t a language, its a building material” by Alan Kay
- “LISP has assisted … in thinking previously impossible thoughts” by Dykstra
Vistor Pattern (Double Dispatch)
- Often used when traversing a tree of heterogeneous objects
- Traversal is not the point of the pattern
- Double-dispatch is point of the pattern.
- Example: use for pretty printing or compiling a tree of syntax tree
- Trying to dispatch to a particular function based on two object hierarchies.
Java Vistor Pattern Example
- Polymorphing is like “Object o; o.display()”
- Non-polymorphing, or overloading, is like “Object o; ((Book) o).display()”
- Could write hand-coded dispatching but maintenance nightmare
- Java cannot direct dispatch correctly a something like DisplayPtr.display(MediaPtr)
- The DisplayPtr subtype cannot be resolved at compile time, so is Non-polymorphing overloading
- Pattern concentrates the grunt code in one place and makes it more maintainable.
- Lisp does this without writing grunt code
Language rants
- Simula and LISP mixed well made SmallTalk by Alan Kay (Good)
- SmallTalk (did he mean Simula) and C mixed make C++ (Bad)
- SmallTalk added message dispatch, now back in CommonLisp
- Methods no longer are member of classes, so organize them well.
Multiple Dispatch
- Explained much better in Wikipedia
- Shows using a pattern in Java that accomplishes the same thing as in Lisp.
- Key aspect is that same pattern can be implemented, but with easy syntax in Lisp.
Error Handling in General
- Pre and post condition testing is not sufficient
- There are ‘actual’ pre/post conditions that cannot be derived from code
- Formal pre/post conditions are what we can derive from code
- Actual pre/post conditions are real corner cases, like file gets deleted during run
- Can open up our expectations and passing error handling upward to a degree.
Error Handling in C, Java, etc
- C uses a ‘return value’ which is often ignored
- Java, Python, etc. propagates exceptions so routine must “handle it or fail”
- Some exceptions need to have decision about how to handle it far up the stack.
- Making that decision in a Java exception system unwinds the stack too early.
CommonLisp Exceptions
- Example is pretty badly described. Think “Top level decides if parse problem is fatal or not.”
- Allows signal of error to be passed up stack independently of unwinding the stack.
- Can use an ‘restart’ method to keep the original stack
- Key aspect is that this is a pattern easier in CLOS, but implementable in other languages
* 55 minutes into video
Macros are the most important feature of CLOS
- The language parser parses into a generic abstract syntax tree
- You can hook your own code generator into the compiler at any scale or level
- These macro hooks expand into lots of Lisp code.
- This allows one to create new syntax and language concepts
- New, compile-time syntax is often best way to express a problem
- Making the pattern explicit in a macro avoids making it implicit in code
