Everything You Ever Wanted to Know about
Common Lisp But Were Afraid to Ask

Laboratory Exercise 4


Artificial Intelligence Laboratory

[ Goals | Background | Pre-Lab | In-Lab | Post-Lab | More Info ]

Goals for the Laboratory Exercise

The goal of this lab is to expose you to more of the vast landscape of Common Lisp and to give you one more week of practice with the language mostly outside the context of an AI program.


"No doubt about it. Common Lisp is a big language." So writes Guy Steele, the foremost authority on the language you are learning. Even if you don't believe him yet, you will by the time you reach the end of this course. Common Lisp is the ultimate "power" language, because it provides tools specialized to nearly any task that you can imagine. The trade-off is this: On the positive side, you can implement incredibly powerful programs with relatively little code by taking advantage of Lisp's built-in functions. On the negative side, in order to do so you need to know about a staggering number of built-in functions, special forms, macros, keyword parameters, ....

Our goal in this lab is to study AI programming. Common Lisp is for us a means to that end, not an end in itself. While we are moving at a brisk pace, the approach suits our purposes well. The first four labs introduce the Common Lisp landscape briefly, so that you will have a point of reference when reading programs later, and then moves right into AI programming.

You will want to treat the chapters you read as mini-manuals. Read them for familiarity with -- not deep understanding of -- each topic, and plan to return to the chapter for closer study when you encounter a program or function later in the course.

Pre-Lab Activities

Prior to doing the in-lab activity, be sure that you have done the following:

  1. Read Chapters 7 and 8 in Graham. Focus on what is available in Common Lisp rather than all the details of every built-in function and special form.

  2. Read this document in its entirety.


Submit by the end of the day Monday an e-mail message that contains answers to the following questions:

  1. Is it possible for two symbols to have the same name but not be eql?

  2. Estimate the difference between the amount of memory used to represent the string "foo" and the amount used to represent the symbol foo.

In-Lab Activities

  1. Use property lists to represent information about basketball teams and their win-loss records from 1996-7. For example, you might include that Chicago went 69-13; Miami, 61-21; New York, 57-25; and Atlanta, 56-26.

    Define a function named find-most-wins that takes a list of symbols as an argument and returns a pair as its output. The symbols in the input should correspond to teams and should have win-loss data attached to their property lists. For example:

         * (find-most-wins '(chicago miami newyork atlanta))
         (CHICAGO 69)

    ... where 69 is the number of wins associated with 'chicago.

  2. Define a function named parse-file that takes as an argument the name of file containing Lisp expressions. parse-file returns as its value a list containing all of the expressions in the file.

  3. Define a function named symbol-print that displays all of the "interesting" aspects of a symbol. These include the symbol's data value (if any), its function value (if any), and any user-defined properties. For example, symbol-print might display a symbol like this:
         * (symbol-print 'foo)
           VALUE: (A B C)
           PROPERTY AGE = 32

    ... where T is the function's value.

    Compare the output of your function to the output of the function describe, which is a built-in function whose output is implementation-specific.

  4. Define a function named tolerance-tester that takes as input a value epsilon. tolerance-tester returns a function of two arguments that determines if the arguments are within epsilon of one another. For example:
         * (setf within-half-p (tolerance-tester 0.5))
         * (funcall within-half-p 1.2 1.4)
         * (funcall within-half-p 1.2 2.2)
         * (setf (symbol-function 'within-half-p) (tolerance-tester 0.5))
         * (within-half-p 1.2 1.4))
         * (within-half-p 1.2 2.2)


Submit an e-mail message (whose Subject: line includes [161]) containing only a single, gcl-loadable file containing your solutions to the above exercises by 4:00 PM on Wednesday, September 26. If you forget what "gcl-loadable" means, please review the instructions in Laboratory Exercise 2.

By that same time, submit a print-out of the same file, to me in person or to the department office.

If you have comments or questions that you would like to send accompanying your submission, please send a separate message.

Post-Lab Exercise

You have read quite a bit now about lambda and various function-manipulating functions.

Sketch out a function (search operators start-state goal-test search-strategy) that implements the generic systematic search strategy that we first studied in Session 4. The goal-test and search-strategy should be functions.

I say "sketch" because I don't expect that you will have a function that is guaranteed to work, if only because we have defined what states and operators look like yet! But your function should load.

Send to me via e-mail your Common Lisp implementation of search as a gcl-loadable file. Your message should reach me by 4:00 PM on Wednesday.

Further Information

Moving this quickly into Common Lisp runs the risk of overwhelming even prepared readers. May I suggest that you supplement your study throughout the semester with frequent references to the texts I have on reserve at the library? As noted earlier, I have in my office a number of Common Lisp texts, including the "bible" (Common Lisp: The Language) and the "dictionary" (Common Lisp: The Reference). The on-line bible is quite a nice service to have free on-line.

Of course, you can stop by my office if you'd like to browse these books, or send me e-mail, if you ever have a question about a Common Lisp construct, or if you want to find out whether Common Lisp has a built-in function to do what you want to do!

Eugene Wallingford ==== wallingf@cs.uni.edu ==== September 19, 2001