STEP 1: LISP Tutorial In this part of the excise, you will load AIMA code into your own directory, and familiarize yourself with emacs and the cs188 Lisp environment. 1. Play with the AIMA code a) get a copy of the code into your home directory. In your home directory, do the following: mkdir cs188 cd cs188 mkdir aima cd aima cp ~cs188/code-2e-188.ZIP . unzip code-2e-188.ZIP You should see a new directory called code-2e-188 created after the unzipping b) Setup the AIMA code cd code-2e-188 pwd Copy down the path name you see on the screen. This is the path you should put in you aima.lisp file. Type emacs aima.lisp to open up the aima.lisp file in emacs. Go down to the 9th line in the file. Redefine the *aima-root* by replace "/home/ff/cs188/code-2e-188/" with the path you see from the previous step. MAKE SURE TO END THE PATHNAME WITH A / Type ctrl-x ctrl-s to save the change. Type ctrl-x ctrl-c to exit emacs. c) Load the AIMA code into Lisp /usr/sww/lang/acl/alisp Once the lisp interpreter is started, type :ld ~/cs188/aima/code-2e-188/aima.lisp You will see something similar to this ; Loading /home/ff/cs188/mytest/code-2e-188/aima.lisp ; Fast loading /home/ff/cs188/code-2e-188/utilities/ansi-cl.fasl ; Fast loading /home/ff/cs188/code-2e-188/utilities/utilities.fasl ; Fast loading /home/ff/cs188/code-2e-188/utilities/queue.fasl ; Fast loading /home/ff/cs188/code-2e-188/utilities/array.fasl ; Fast loading /home/ff/cs188/code-2e-188/utilities/probability.fasl ; Fast loading /home/ff/cs188/code-2e-188/utilities/statistics.fasl ; Fast loading ; /home/ff/cs188/code-2e-188/utilities/test-utilities.fasl Now the aima lisp code is loaded. Do the following (aima-load 'agents) (test 'agents) You should see tons of output, and make sure you get a 0 at the end to indicate that your version of the code is working. You can exit the lisp interpreter by typing :exitUsing LISP in emacs d) Setup the emacs editor for running LISP chdir ~/ emacs .emacs Insert the following lines to the top of the file (setq inferior-lisp-program "/usr/sww/lang/acl/alisp") (global-set-key "\C-x\C-l" `run-lisp) (global-set-key "\C-xd" `lisp-eval-defun) (global-set-key "\C-x\C-d" `lisp-eval-defun-and-go) Save and exit by typing ctrl-x ctrl-s and then ctrl-x ctrl-c e) Run LISP. do the following to get a copy of lisp code that you can play with cd cs188 mkdir a0 cd a0 cp ~cs188/temp/a0-dumb-solution1.lisp . Open up the file you just copied using emacs: emacs a0-dumb-solution1.lisp Type ctrl-x ctrl-l in the emacs window. You will see a new buffer is created and connected to a Lisp process. f) Load a LISP program Inside emacs, type ctrl-x b, and then hit ENTER to switch back to the code. Type ctrl-x ctrl-d to load the program, and you should be taken back to the LISP buffer. You can also see a line “TWO-TO-THE” appears on the prompt. Now the function is loaded, play around with it, for example, try (two-to-the 4). Is the output correct? Now type Esc-p, what do you see? Note that this is the way to get back the last command line you typed. g) Modify the lisp program Now switch back to the program buffer using ctrl-x b. Add the following line (format t "n = ~s~%" n) to the definition of the function TWO-TO-THE. (Insert it right after the defun line) Reload the program by using ctrl-x ctrl-d. Run the program again by typing (two-to-the 4). What do you see this time? h) Tracing and Debuging LISP program Make sure you are in the LISP buffer. If not, type ctrl-x b to switch. Type (trace two-to-the) (two-to-the 4) to trace the function. You can now see how the stack looks like on each recursive call to TWO-TO-THE. "0[1]: (two-to-the 4)" means the 0th function on the stack, and "0[1]: returned 4" means that the 0th function on the stack returned with a value "4". Since this is a recursive function, we get a nested structure. Type (untrace) to stop the function been traced.Go back to the buffer where you have the code. Replace (format t "n = ~s~%" n) with (break). This sets up a break point. Reload and run the function. At the break call type :continue 0 to continue past the break point. Type :continue 0 again. This time type :zoom or :up to see the stack
View Full Document