CSE 341 -- Assignment 1

October 2, 1995
Due in quiz sections October 10, 1995


  1. Experiment with the Common Lisp system a bit. Try the built-in functions that we discuss in class, including +, first, rest, cons, length, equal, and not. You don't have to hand in anything for this question.

  2. Draw a box-and-arrow diagram showing the result of evaluating the following Lisp expressions. (It's OK to check your answer by trying this on the computer, but you don't need to.)
    1. (cons 1 (cons 2 nil))
    2. (list 1 2)
    3. (cons (cons 'x nil) (cons 'x nil))

  3. Describe in your own words the difference between type safe and not type safe, and also statically typed and dynamically typed. Give an example of a function in Lisp that has a type error in its body. When would the error be detected? (Try it.) When would the error be detected for an analogous function in Ada or C? (Pick whichever language you know.)

  4. Write and test a Lisp function number-stuff that takes a single floating-point argument n and returns a list consisting of n, n squared, n cubed, and the square root of n. Example:

    (number-stuff 3.0) evaluates to (3.0 9.0 27.0 1.7320508)

    You don't need to worry about checking for non-numeric or negative arguments.

  5. Write and test a Lisp function next-color that takes a symbol (one of green, yellow, or red) representing a stoplight color, and returns the next color in the light's sequence. If the argument isn't one of these symbols return the atom huh. Examples:

    (next-color 'green) evaluates to yellow
    (next-color 'yellow) evaluates to red
    (next-color 'red) evaluates to green
    (next-color (next-color 'green)) evaluates to red
    (next-color 'purple) evaluates to huh