The Department of Computer Science & Engineering
cse@buffalo

CSE202: Programming in Lisp

Course
Grades
Email

Welcome

Policies
    Grades
    Inc
    Intgrty

Preface
Part I
  Chap 1
  Chap 2
  Chap 3
  XEmacs
  Chap 4
  Chap 5
  Chap 6
  Chap 7
  Chap 8
  Chap 9
Part II
  Chap 10
  Chap 11
  Chap 12
  Chap 13
  Chap 14
  Chap 15
  Chap 16
  Chap 17
  Chap 18
  Chap 19
  Chap 20
  Chap 21
  Chap 22
  Chap 23
Part III
  Chap 24
  Chap 25
  Chap 26
  Chap 27
  Chap 28
  Chap 29
  Chap 30
  Chap 31
  Chap 32
CHAPTER 12: SAVING FOR ANOTHER DAY
Notes
  1. Read Chapter 12, along with these Notes.

  2. You have been using XEmacs since Chapter 4. You have mainly been using the Inferior Common Lisp mode to interact with the Lisp listener. You have also been using the Common Lisp mode to prepare the .cl files you have been submiting.

    Starting now, you will also be using XEmacs to create and edit files of Lisp source code. Lisp source files should also have the extension of .cl, and you should edit them in the Common Lisp mode, which XEmacs will set automatically whenever you edit a file that has the .cl extension, whether or not that file previously existed.

    XEmacs will also recognize files with the .lisp extension as Common Lisp source files, but let's be modern and use .cl

    Some useful commands available in Common Lisp mode are:

    Close all open parentheses or eliminate extra right parenthesesC-c ]
    Comment out regionC-c ;
    Complete Lisp symbolM-TAB
    Re-indent current lineTAB
    Re-indent S-expressionM-C-q
    To previous first-column "("M-C-a
    To beginning of enclosing listM-C-u
    Forward one S-expressionM-C-f
    Backward one S-expressionM-C-b
    Kill one S-expressionM-C-k
    Evaluate enclosing defunC-u M-C-x
    Evaluate bufferC-u C-c C-b
    (Note that M-C-a means hold down both the meta and the control keys while typing an "a", or first type the escape key and then hold down the control key while typing an "a".) Remember, you can see all the commands available in whatever mode you're in by typing C-h m

  3. The text introduces the load function on page 78. To load a file from the Lisp listener, you can evaluate
    (load "filename")
    or use the acl command
    :ld filename
    If you use the :ld command, you can type the filename with upper- and/or lower-case characters, exactly as you created it, without using quote marks or escape characters.

    ACL compiled files have the extension .fasl Unfortunately, if you try to load a file, and don't type its extension, and there is both a .cl file and a .fasl file, acl will load the .fasl file, even if the .cl file is newer.

  4. Filenames can be complete paths. For example, you can do
    (load "~/CSE202/ch12")
    or use the acl command
    :ld ~/CSE202/ch12
    Of course, if you specified ~/CSE202 as the Process directory when you executed M-x run-cl you don't need to include that part of the path. You can see what "Lisp's current working directory" is by typing the acl command
    :pwd
    and you can change that directory by typing the acl command
    :cd directory path

  5. If you are editing a Lisp source file, an even easier way of loading it into your Lisp environment is, with your cursor in the source file buffer, type C-u C-c C-b

  6. On pages 80-81, please remember that the Common Lisp we are using abides by the new standard (ANSI Common Lisp), so use the defpackage form rather than the forms shown on lines 4 - 26 of page 80.

    You should include only the defpackage subforms you need, or include them all and comment out the ones you don't need.

  7. The book has two sets of exercises, each of which forms a "term project". Everyone is to do project p1 because students in the past have had a lot of trouble with project p2. The p1 project is a small rule-based system and a mini-version of Eliza.

    In preparation, you should browse the overview and specification of project p1, which is available as a dvi document, and as a PostScript document.

    A version of Eliza that is much more complete than the one you will write is available within XEmacs by typing M-x doctor Try it. Pretend you are a patient talking to your psycotherapist.

Exercises
  1. Create a file named match.cl containing the following, with appropriate information replacing the question marks.
    ----------------------- cut here -----------------------
    ;;; The MATCH file
    ;;; by ???
    ;;; begun on: ???
    ;;; as answers to Project p1 in
    ;;;      S. C. Shapiro, Common Lisp:  An Interactive Approach,
    ;;;      Computer Science Press, 1992
    ;;;
    ;;; This file satisfies the exercises through Exercise ???
    ;;;
    (defpackage match)
    
    (in-package match)
    
    ----------------------- cut here -----------------------
    

  2. Do Exercise 12.2.

  3. Compile your match.cl file either according to the directions given in Exercise 12.3, or simply by doing
    :cf filename
    
    If you get any warnings or error messages from the compiler, edit your source file to correct the problem, and recompile it.

  4. Do Exercise 12.4 using the :ld command. Test the compiled version of the function you wrote.

  5. Submit the .cl file you wrote for this Chapter.

Next

Copyright © 1999, 2000 by Stuart C. Shapiro. All rights reserved.

Stuart C. Shapiro <shapiro@cse.buffalo.edu>