CSci 431

Exercise set #1

Due:  Friday, Sept. 17

10 pts.


Write solutions for the following problems in common lisp. Turn in a hardcopy of your solutions.

You should check your answers on your favorite implementation of LISP, but try to write the solutions to the problems before doing that (you will not have access to ACL during exams)


Some basic problems:

  1. Write as dotted pairs
    • (a b c)
    • (a (b c))
    • (a (b c) d)
  2. Write as lists
    • (a . ((b . nil) . nil))
    • (a . ((b . nil) . nil))
    • (a . ((b . ((c . nil) . nil))))
    • (a . ((b . nil) . (c . nil)))
Some programming problems. 

None of these functions should make any changes to the arguments.  Points will be deducted for unnecessary input and output statements, and for unnecessary use of local/global variables. Use recursion whenever possible.  None of these functions should make any changes to the arguments. You may use helper functions, but these functions should be otherwise self-contained.

You should keep in mind that several of these functions mimic established LISP functions.  The idea is for you to learn how these functions might be implemented recursively, so don't use the built-in function.

  1. Write a function with computes the average of two numbers.  Returns the average.
  2. Write a function (max2) which finds the maximum of two numbers.  Returns the maximum.
  3. Write a function which swaps the first two elements of a list.  Returns the list with the first two items swapped (without making any changes to the argument).
  4. Write a function that mimics the built-in append function of common lisp.  Returns the resulting list.
  5. Write a function that mimics the built-in reverse function.  Returns the resulting list (hint (I hope):  use append).
  6. If we don't do Fibonacci in class, do the Fibonacci function. If we do, find a reference for Ackerman's function and do that.

Any questions? Please ask!