Notes and hints on Programming Project 3
Corrections and additions to the original assignment handed out in class:
- (2) count is a builtin function. Some versions of common
lisp won't let you redefine this. Ours will, but it may cause further
problems. To get around this, call the function count1 , as
done in the test data.
- (10) you should write both programs, one each for parts (a) and (b), but
you only need to name one of them average and have it work.
- (12) should be (all_nths n lol) - the assignment left
out the n.
- (14) the return value should be a list of the columns of
the matrix, not rows, as stated (that would just give you the same
lol as the input).
Check the test data return values for more information.
- Functional Programming: The purpose of the lisp material
in the course (and this assignment) is to teach functional programming
and recursion. Common lisp actually has functions to set the values of
variables and even a do loop. Don't use
them! You can do everything you need using only function
calls to helper functions if you need to update values to
variables. In particular, points will be taken off for using
setq, set or setf inside your programs. You also
shoudl avoid using the built-in functions that calculate the same or
similar fucntions as the ones described here (e.g., nth,
count, length). You may, howeve ruse any of the
recursive functions or primitives we discussed in class, such as member.
- Error Checking: in general you can assume for these
programs that data will be of the correct type (positive integer,
list, list of lists). You do have to check the base cases, though.
For example, you always need to check to see if a list is empty
before taking the car or cdr. For
list of lists, this includes both nil (a list of zero lists), and
something of the form (nil nil ... nil), e.g., a list of empty
lists.
other notes
- The original test data had a couple errors, make sure you get a
copy after 3/11. In particular the return from
(nth_item 2 '(a b c d)) should be B not BC
- The comment symbol in lisp is ;
lisp will ignore
anything after a semicolon on a line.
- To return the symbol *error* (or any symbol for that
matter), use the quote special form, described in class: either
'*error* or (quote *error*)
- The emacs editor is very useful for interactively writing and
debugging lisp programs:
- For one thing, it will let you run lisp
inside the editor (type to emacs M-x run-lisp ), where you can
edit what you type in to lisp, and
whenever you hit return, it will evaluate the s-expression just to the
left of your cursor.
- Even more useful: you can edit your definitions in one buffer
(the file you will be saving), and you can send a single s-expression
(e.g., a defun) to the lisp listener by typing M-C-x (that's
escape followed by and x together). This saves you having to
load in a whole file each time you make just one change.
- Emacs has a built in tutorial and extensive on-line help.
- here are some pointers to short emacs help locations: