CSU520 Artificial Intelligence - Spring 2006 - Lisp Quiz
A kindler, gentler Lisp quiz
Professor Futrelle -
College of Computer and Information Sciences, Northeastern U., Boston, MA
Updated 24 January 2006
The Lisp Quiz will be, Monday, January 30th (last 30 minutes of class)
Here is the
earlier review for the quiz,
posted January 22nd. The material below is a more accurate indication of
what you will be quizzed on. It is much simpler than the earlier review.
This quiz is closed book and focused entirely on the material
in Chapter 1, Introduction to Lisp, in PAIP.
The material is so basic, that you are responsible for all of it.
On the other hand, the quiz is being given to see that you have
a reasonable acquaintance with Lisp, not that you have mastered every
item in the chapter. Therefore you will still be given a score of
10 out of 10 even if you miss a few items. How's that? ;-)
Some of the observations below are based on what I learned from grading
the CSG120 quiz given Monday the 23rd.
How to study for the quiz
Practice writing out expressions without looking at the book.
Then check them using PAIP or other Lisp references such as
Seibel's on-line book, and then by entering them into lisp.
Do this over and over until you get them right every time.
Basic design of the quiz
Rather than asking you to design nontrivial functions that use the basic
lisp functions and forms, the quiz will focus on the basic Lisp functions
and forms themselves. There will be questions that combine various of the
basics, but not in complex ways. I also may give an ill-formed expression
and ask you to write a proper version of it.
Here are some of the more important basic Lisp functions from Chapter 1
of PAIO, not an
exhaustive list. In each case you'd be asked to show a simple use or
state what the result of an example use would be.
- Use setf.
- Append lists.
- Compute length of a list.
- Use defun.
- Use first, second, and rest.
- Use cons.
- Use list.
- Use mapcar with a function of two arguments.
- Use apply and funcall properly - they are not the same.
- Use a lambda application or a funcall of a lambda.
Common mistakes and misunderstandings to avoid
- When a list is returned it is rarely quoted.
Eval of ''(a b) would be '(a b) - correct, but odd.
- Functions of two arguments are sometimes used or
funcalled on a single argument - Wrong.
- If you don't quote a symbol, Lisp will use its value.
- It's a mistake to write or print so poorly that I can't read it.
- Functions are prefix - you can't sum two numbers with +(1 5) or
(1 + 5). You must write (+ 1 5).
- If you don't quote the list '(a b c d), Lisp will attempt
to apply the function 'a' to the three arguments, b, c, and d.
- Confusion about #', shorthand for (function ...).
If you map or apply or funcall
a named function, say myfun, it must appear as #'myfun.
But if the function myfun was passed in as an argument then it had
to be passed in the form #'myfun, so when the argument is
used inside the function definition, it is "already" a function
and does not need the #'. Both cases are illustrated in the mappend
function on page 19. The same applies to a lambda - it must
be mapped or applied or funcalled with #'. If it appears in
the function slot, e.g., ((lambda (x) ....) 3) it does
not need the #'. Or if it is passed in by a function the
argument variable can be mapped, applied, or funcalled with or
without the #'.
What you can not do is to take a function passed in,
e.g., by an argument 'fn', and place it in the function position.
So the following does NOT work:
(defun boo (fn)
(fn 3)) ;; No, No, No.
Lisp will complain twice about this. It will say that the argument fn
is not used and it will say it can't find the function definition of fn.
A correct version would be:
(defun boo (fn)
(funcall fn 3))
An example of a valid use of boo is:
(boo #'(lambda (x) x))
which returns 3.
Go to CSU520 home page.
or RPF's Teaching Gateway or
homepage