Programming Environment for AI Courses
Last modified: "January 13, 1997 20:05:53 by matt"
Obtaining Your Very Own Lisp
Of course, you are welcome to make use of the departmental facilities for
your programming assignments, including Lisp. If, however, you are
interested in obtaining a version of Lisp to run on your home computer, I
suggest you look over section of the Common
Lisp FAQ pertaining to free implementations of Common Lisp. For PC
users, Franz's Allegro CL would seem to
be a good bet. (A copy of the executable, split into 4 zip files is here.)The freeware version of the
program is limited, but should suffice for our class. If you've got the
dollars, you can upgrade to a full implementation. Another alternative that
a lot of folks have had success with is to run Gnu Common Lisp on Linux.
For Macintosh users, the best shareware version of Lisp is
PowerLisp. If you can afford the $135, I heartily recommend Digitool's
Macintosh Common Lisp. It is the
best implementation of Lisp I have seen anywhere, bar none. The commercial
releases of both Allegro CL and MCL are full application development
environments: debuggers, compilers, GUI construction kits, etc.
Emacs is Number One!
I recommend using emacs19 to do your
programming. Forget that ancient and obsolete VI stuff! Emacs is the
happening place! To run emacs19 just use the 'emacs19' command in the
departmental Unix environment. (When not working in an X windowing
environment, run version 18 of emacs, via the 'emacs' command.)
Learning emacs
Emacs is the world's most powerful editor, but this comes at a price:
Emacs has a steep learning curve. I have been using emacs for 13 years, and
pick new stuff up all the time. Still, you only need to know a little about
the editor to use it. You will pick up more powerful features as you become
more comfortable with the editor. There are four good ways to learn about
emacs:
- Run the emacs tutorial. To do this, use the Help menu, or just type
C-h t.
- Check out Keith Waclena's Web-based emacs tutorial.
- Use emacs' built-in Info facility. C-h i. Use the middle
mouse-button to select topics.
- Ask other emacs users. If you see somebody doing something neat, ask
them how they do it.
Modifications to Emacs for Common Lisp
There are a
couple of modifications you should make to your emacs environment to make
it Common Lisp friendly:
Put the following code in your .emacs file (before fiddling with your .emacs files, always make a copy someplace safe, in case something goes wrong):
(defvar emacs-is-version-19 (>= (string-to-int (substring emacs-version 0 2)) 19))
(if emacs-is-version-19
(progn
(load "completion") ;Turn on completion mode
(initialize-completions))) ;This defines M-Ret as complet.
(cond (window-system
(setq hilit-mode-enable-list '(not text-mode) ;Enables hilighting in all modes except text
hilit-background-mode 'light
hilit-inhibit-hooks nil
hilit-inhibit-rebinding nil)
(require 'hilit19)
))
(defun my-lisp-mode-hook-fun ()
(set-fill-column 110)
(setq comment-column 48))
;;; This shell-strip stuff removes the "^M" which would otherwise appear at the end of
;;; every line of output in any shell buffer, including inferior-lisp buffers.
(defun my-comint-mode-hook ()
(require 'shell)
(cond ((not (member 'shell-strip-ctrl-m comint-output-filter-functions))
(setq comint-output-filter-functions (cons 'shell-strip-ctrl-m comint-output-filter-functions)))))
(if (boundp 'comint-mode-hook)
(if (listp comint-mode-hook)
(if (not (member 'my-comint-mode-hook comint-output-filter-functions))
(setq comint-mode-hook
(append comint-mode-hook '(my-comint-mode-hook))))
(setq comint-mode-hook
(list comint-mode-hook 'my-comint-mode-hook)))
(setq comint-mode-hook (list 'my-comint-mode-hook)))
(if (boundp 'lisp-mode-hook)
(if (listp lisp-mode-hook)
(if (not (member 'my-lisp-mode-hook-fun lisp-mode-hook))
(setq lisp-mode-hook
(append lisp-mode-hook '(my-lisp-mode-hook-fun))))
(setq lisp-mode-hook
(list lisp-mode-hook 'my-lisp-mode-hook-fun)))
(setq lisp-mode-hook (list 'my-lisp-mode-hook-fun)))
Okay, with the above code in place, you should be able to run Lisp from
within emacs. Use the command
A separate buffer should spring up with Lisp running inside it. You can type directly into this window and it should be just like working in an xterm, but better. Improvements include:
- M-p and M-n implement a command history. They rotate through previous commands in the Lisp window.
- M-s and M-r work with the history, looking for a command whose prefix matches the current command line..
- C-x C-e This two-key sequence evaluates the s-expression preceding the cursor. Typically you use this command from within a buffer containing actual lisp code. It will copy the s-expression into the Lisp buffer to be evaluated there.
- M-return is part of the completion system. If there are at least three non-space characters in front of the cursor, emacs will replace that character sequence with the most recently referenced symbol having that prefix. Repeated M-returns will rotate through all symbols matching that prefix. The completion functionality should work in all buffers, by the way, not just in Lisp. This extremely powerful feature should allow you to work with fairly long, mneumonic symbol names, as you won't have to type them more than once. You can use the completion facility for subsequent references.
- The TAB key should properly indent a line according to mode. So if you are working in a Lisp buffer, it should indent the line properly for a Lisp program.
- M-C-q Will indent an entire s-expression. Just place the cursor on the leftmost parenthesis of the s-expression to be indented. Usually this is the left paren just before a DEFUN.
For a complete list of the commands within the Inferior Lisp environment (as it called,) type C-h m within the inferior lisp buffer.