frost.umd.edu holmes.umd.edu koko.umd.edu maigret.umd.edu marlowe.umd.edu marple.umd.edu morse.umd.edu poirot.umd.edu tracy.umd.edu wolfe.umd.edu
(defconstant +sales+ '((ann 4 2 3 0 4) (betsy 1 4 0 0 0) (carol 0 1 2 3 4) (dawn 1 3 5 1 0) (ellen 0 0 0 0 0) (fran 8 1 7 8 5)) "Data on Girl Scout cookie sales over five-day sale period")Notice that +sales+ is a list containing six elements, and each element is itself a list containing information about one of the girls.
Two of the girls, Ann and Dawn, are sisters, and they're very competitive. So competitive that they've decided someone needs to write some LISP code to determine who sold more cookies this year. Being good programmers, they've decided to organize the task in a very general way, so that it's easy to get and compare information about any of the girls' sales. To make things easier, they've gotten their mom to write the first function they need, which takes a list of numbers and sums it up. She wrote:
(defun sum (numlist) "Adds up the numbers on the list" (if (null numlist) 0.0 (+ (first numlist) (sum (rest numlist)))))
Rather than typing in +sales+ and the definition of the sum function, you should copy a file that contains them into your local directory by doing the following to use the "ftp" program on the AITS machine:
% ftp umiacs.umd.edu
Name (umiacs.umd.edu:pr44300): anonymous
ftp> cd pub/resnik/ling689
ftp> get lab1.lisp
ftp> quit
Now that you've got file lab1.lisp, you should bring it up in a text editor: your job is going to be to write the rest of the LISP code the girls need. To work most efficiently, you'll want to be able to easily go back and forth between your text editor and a Unix window where you'll be running LISP. Here are a couple of ways to do this.
emacs lab1.lispin one of them. The result should be a window for the emacs editor. You should also still be able to work in the other telnet window, so you can execute
lispthere to start lisp. Now you should just be able to go from window to window. (Usually you click on the title bar of the window to select it, but that varies from system to system.)
(load "lab1")This is just the same as if you'd just typed all of lab1.lisp into the LISP environment. Type
(describe '+sales+)to see information about that symbol.
;;;;;;;;;;;;;;;;;;;; ;;; My Name Here ;;; Ling689A Lab 1 ;;; Today's date ;;;;;;;;;;;;;;;;;;;;
Now you're ready to do some programming. First, define a function called average. It should take a single argument, which you may name anything you like. That argument will be a list. The value returned by the 'average' function should be the average of the numbers on the list; that is, you're going to take the sum of the numbers on the list and divide it by how many numbers were on the list.
If you're having difficulty getting started, draw a boxes-and-arrows diagram using Touretzky's notation. What are the pieces you need? What are the inputs and outputs for each piece? How can you connect these? If you're helping someone who's stuck (this is a note for the assistant and/or any students who have easily solved this), what I'd like you to focus on first is helping them get a correct boxes-and-arrows diagram written, then on the LISP notation for the sub-pieces, and then on writing the whole function definition.
At any point in time, you can save lab1.lisp, go back to LISP, and re-execute
(load "lab1")This will re-load the file with the new changes. Note that you may get errors when you re-load the file. That's ok. The best thing to do is to read the error message, quit out of the debugger, and go back to the editor to fix the file. Then save your changes, go back to LISP, etc. This is called the edit-debug cycle. (Get used to it...)
If your edited LISP code works correctly, you can then test the function, e.g. by evaluating:
(average '(1 2 3 4))If you've done your Touretzky reading, you'll realize we're putting the quote symbol in front of the list to make sure that there's no attempt to evaluate 1 as a function, with 2, 3, and 4 as its arguments!