Common Lisp/Case Studies in CL

From Wikibooks, open books for an open world
Jump to navigation Jump to search

The purpose of this chapter is to provide a set of in depth examples, or case studies, in implementing programs in Common Lisp. The goal here is to provide some a taste of what a full fledged Common Lisp application might look like. This is important as a typical Common Lisp application usually doesn't look like many little parts tacked together. The unique level of abstraction that the programmer can achieve in Common Lisp tends to promote programs that tailor the language to the purpose, and leads to overall efficiency of development.

A secondary purpose for this chapter is to highlight some packages that were passed up in other sections. Some Common Lisp applications/projects, for whatever reason, just didn't fit in elsewhere in this book. Some were excluded because a Common Lisp beginner wouldn't find it interesting, others due to a large learning barrier to using them and too much text would be required to explain, and even others still that are perhaps unstable due to recent development or stagnant and suffering from bitrot. These projects still have some very cool parts to them and now that you have a firm footing in everything Common Lisp, we can introduce these packages and spend the extra time explaining what is necessary.

Writing Web Applications[edit | edit source]

It is no secret that there is a lack of portable GUI solutions for the Common Lisp language. We have previously discussed LTK, which works for anybody with wish installed, but is annoyingly slow for some applications. There is another route to providing a GUI and that is through a web browser. The web technology of dynamic web pages (javascript + AJAX + server side programs) has progressed to the point where it is more than ample for the most GUI functionality. A lot of work has gone into making it look the same on any computer that runs a browser. Further, you can trivially make your applications run both locally and remotely. Of course, it is also fairly wasteful of CPU and memory, but c'est la vie.

  • A web based game in Common Lisp

Further reading[edit | edit source]

  • WebBlocks
  • Uncommon Web (UCW)

Solving NP Problems, Nondeterminism[edit | edit source]

Bear with us, since this is a rather computation theory intense subject. By writing nondeterministic code, one can trivially write down a solution to an NP problem. There is no such machine that can execute that code in polynomial time, but there are nondeterministic emulators that can execute the code in exponential time. Even though such an emulator would take a very long time to find a solution given a large enough input, it is still useful prototype a dumb implementation in a few minutes. More importantly, however, this prototype can be developed to provide better performance or use approximations to find near solutions efficiently.

Several languages have nondeterministic emulators. Prolog (via backtracking search) and Scheme (via continuations) come to mind. Common Lisp has a package that provides this functionality; it's called Screamer. We have discussed Screamer before, but it warrants further in depth examples. Screamer performs what's known as CPS transformation on your code, producing an emulation of the nondeterministic behavior.

  • Do something neat with Screamer

Further reading[edit | edit source]

Screamer on CLiki

Context Oriented Programming[edit | edit source]

Context Oriented Programming is a new paradigm of programming where the context in which code is executed modifies what it does. The designers envision it as further development of the ideas that Object Oriented Programming and Aspect Oriented Programming were meant to address.

  • Do something with ContextL

Further reading[edit | edit source]

Computer Algebra and Automated Theorem Proving[edit | edit source]

Earlier dialects of Lisp pioneered work in Computer Algebra (computer aided manipulation and solving of algebra and calculus problems) and Automated Theorem Proving (computer aided proofs of mathematical theorems).

  • A mathematical simplification program
  • Using Common Lisp from Maxima and Maxima from Common Lisp
  • Proving with ACL2

Further reading[edit | edit source]

  • Maxima — A computer algebra system written in Common Lisp. It is a descendant of DOE Macsyma.
  • ACL2 — An automated theorem prover