Skip navigation

Category Archives: Scheme

AI programming has traditionally been associated with lisp. There are some AI paradigms where this makes a lot of sense because of their use of symbolic representation: logic and constraint satisfaction, planning, natural language understanding.The connection is a lot less clear for connectionist and roboticist approaches.

Lisp is really a family of languages. Common Lisp is huge, a bit dated, but includes the most powerful features for object-oriented programming (CLOS) of any programming language I know. There are a number of flavors of Scheme. Scheme is a minimalist version of lisp with a stronger emphasis on the use of functional programming.

One of the advantages of all lisp dialects is that the program code is itself is written as data that is easily processed by Lisp programs. This leads to “macros”, small programs that extend the syntax and semantics of the programming language. A common strategy is to write tiny compilers for language extensions that generate lisp code and then let the lisp compiler compile that into efficient machine code. If you say, want to add Prolog-like logic programming to a lisp you can do that. This strategy has gained quite a bit of popularity in other language communities (for example Ruby) where it is used to implement “domain specific languages,” that is small nested languages that facilitate writing programs about specific application areas.

Traditionally Common Lisp has been the language of choice for AI programming. In my past life I really enjoyed writing CL programs with tens of thousands of lines of code. But I have always gravitated towards Scheme dialects. I think it is both that I am very comfortable with a functional style and attracted to Scheme’s minimalism. One AI researcher I know pointed out that Peter Norvig’s classic book “Paradigms of Artificial Intelligence Programming” uses Common Lisp with a style that is more common to scheme programmers. If so, I am in good company.

There are truly impressive optimizing compilers for both Common Lisp and Scheme. With a little work compilers such as SBCL (Common Lisp) or Gambit-C (Scheme) can generate code that is in the speed ballpark with optimized Java or C. (for example see http://shootout.alioth.debian.org/gp4/lisp.php) In many application areas, however, its a good idea to get a program working before making it fast. Depending on the algorithms you are using, the constant factor speedup you get by having a better compiler might or might not help you solve larger problems.

One of my favorite Scheme dialects is PLT Scheme. It is both a very approachable system (designed to help beginning programmers get started) but also a powerful tool for people who have advanced skills. The system has been advancing very rapidly of late with better memory management for long-running programs, integrated web server, faster generated code, and some good additions to the standard features of the language.

Clojure is a new dialect of lisp that manages to combine some of the best features of Common Lisp and Scheme. Clojure runs in the Java Virtual Machine, so it has access to the JVM’s very very extensive library (you can get almost anything you want..) and it makes it that much bit easier to integrate AI code into existing “enterpise” applications. One of my goals with AI Renaissance is to bring AI programming techniques to real world applications, so this is important.

Clojure emphasizes functional programming with a unique and interesting method of dealing with data in threads. Some day very soon we will have computers with many cores so there is a real advantage in tools that can take advantage of multi-processor machines. Otherwise, Clojure feels very much like a Scheme with a macro system that is a bit closer to Common Lisp’s.

I suspect I will be using PLT Scheme and Clojure on this blog and very much I recommend both.