Programming Assignment #2

Last modified: "December 9, 1996 16:49:23 by matt"

From Graham's ANSI Common Lisp: Ch.5: 5,7; Ch.6: 3,7,8 (for 7 & 8 don't use a global variable); Ch.7: 3,4
5.5 Define iterative and recursive versions of a function that takes an object xand vector v, and returns a list of all the objects that immediately precede x in v:
> (precedes #\a "abracadabra")
(#\c #\d #\r)

5.7 Define a function that takes a list of numbers and returns true iff the difference between each sucessive pair of them is 1, using

  1. recursion
  2. do
  3. mapc and return
6.3 Define a function that takes any number of arguments and returns the number of arguments passed to it.

6.7 Define a function that takes one argument, a number, and returns true if it is greater than the argument passed to the function the last time it was called. The function should return nil the first time it is called.

6.8 Suppose expensive is a function of one argument, an integer between 0 and 100 inclusive, that returns the result of a time-consuming computation. Define a function frugal that returns the same answer, but only calls expensive when given an argument it has not seen before.

7.3 Suppose that in some format for text files, comments are indicated by a % character. Everything from this character to the end of the line is ignored. Define a function that takes two filenames, and writes to the second file a copy of the first, minus comments.

7.4 Define a function that takes a two-dimensional array of floats and displays it in neat columns. Each element should be printed with two digits after the decimal point, in a field 10 characters wide. (Assume all will fit.) You will need array-dimensions.