This is a Week1 | Lab page, written Wed Jan 9 11:48:41 PST 2008.
This week we learn about an AI development environment (EMACS) and a little about an
AI language (LISP), and how to run and test our code.
Note that this is NOT a semantic exercise. You'll be looking at a lot
of code in a language you may have never seen before (LISP).
Don't try to understand the details- its just the big picture on how to edit and
code and test cases that is important here.
You have an hour to attempt the following 24 exercises.
Don't hand anything in. But I will be asking you to perform for me a few
randomly selected items from this list.
If you can't complete that task,
please do so before next week. You'll need this work before you can start
Project1
Directory and Files
To begin, you need to:
- set up some directories and download some files.
mkdir -p $HOME/opt/lisp
cd $HOME/opt/lisp/
svn export http://unbox.org/wisp/var/timm/08/ai/src/week1 week1
If that works, you should see something like:
A week1
A week1/code.lisp
A week1/eg.lisp
A week1/make.lisp
A week1/macros.lisp
A week1/config.lisp
A week1/lib.lisp
A week1/demos.lisp
Editor
Now, we need to set up your editor.
- Edit the file $HOME/.emacs and add the code
shown in getting started with SLIME. Quit that editor.
Now, fire up emacs.
cd $HOME/opt/lisp/week1
emacs &
Show the instructor you can work that environment:
- Split the screen (Cnt x-2)
-
Move cursor from one screen to another.
- Edit difference files in each split (Cnt x-f).
-
Un-split the screen (Cnt x-0)
-
Cut copy, paste text (look at the Edit menu)
-
Save files (Cnt x-s)
-
Write a buffer to a new file (Cnt x-w)
-
Revert a buffer, throwing away all changes. (Look at the "File" menu).
-
Quit (Cnt X-C).
- Edit some code
cd $HOME/opt/lisp/week1
emacs make.lisp &
If that works, you should see something like:
Language
Once you can edit code, you need to run an interpreter.
- While editing make.lisp,
type "Meta-X slime " (where "Meta-x" means
hold down the Esc key and type "x").
After a few seconds your should be looking at the
LISP's "read-evaluate-print" (or REPL) prompt:
; SLIME 2006-04-20
CL-USER>
- Try and reproduce the following screen.
- LISP functions do something then return the last thing they evaluate. So
why do we see "hello world" twice in the above screens.
- Split the screen (remember how?) and get the REPL and make.lisp on the same
screen. Place the cursor in "make.lisp" and load that file into LISP (hint:
menu : SLIME : Compilation : Compile/Load File).
- Edit "lib.lisp" and write your name at the top as a LISP comment
;;;; Tim Menzies
- Reload all changed files. How? Well "make.lisp" knows all the files required
for this program. That remake is called by the "(make)" function. Go to the REPL and type
CL-USER> (make)
Systems
The list of files at the top of "make1.lisp" are pretty standard. You could find them in
any language:
(mapc 'make1
'(eg ; unit tests
lib ; generic stuff
config ; configuration
macros ; macros
code ; main code
demos ; stuff to show off
)
- Look at the list of unit tests at the end of "eg.lisp". Add a test that
checks if "(+ 3 7)" returns 11. Run that test with
CL-USER> (make)
CL-USER> (demo :demo)
- In LISP, and association list is a list of pairs "((key1 . value1) (key2 . value2) etc)".
Updating that list is a little tedious; e.g. "(assoc key list)"
find the pair that contains "key";
and "(cdr (assoc key list))"
finds the value in the pair than contains "key" value in list;
and to increment some key's value (by one) there are all these special cases like
the key is not in the list. So I wrote some code to simplify talking to association lists.
Look at the list of unit tests at the end of "lib.lisp". Run them and take
a guess at what is going on
CL-USER> (make)
CL-USER> (demo :assoc)
- Take a look at "config.lisp" and guess what is going on there. Look up
the difference between
defvar
and defparameter
and make a case why you should, should not use defparameter or defvar.
- Take a look at "macros.lisp" and guess what is going on there.
CL-USER> (make)
CL-USER> (demo :o)
- Take a look at "code.lisp" and write another function that reports what
we have nothing to fear but.
(defun we-have-nothing-to-fear-but ()
"fear itself")
Make those changes and check out what you have to fear.
CL-USER> (make)
CL-USER> (we-have-nothing-to-fear-but)
- Take a look at "demos.lisp" and add "we-have-nothing-to-fear" to the list of demos
in that file. Run them all.
CL-USER> (make)
CL-USER> (demo :week1)
Congratulations!
Now you can edit and run LISP code and write little unit tests and combine them up
into one large systems test.