Homework Assignment 4.
CS 316, Spring 2008.

Due on Thursday, February 28, 2003.


1.) Write a tail recursive version of the procedure make-list
from Assignment 1 (i.e., Exercise 2.8.3).


2.) Here is a recursive procedure which computes x raised to the
power y, where x can be any number and y is a positive integer.

(define pow
  (lambda (x y)
     (if (= y 0) 1 (* x (pow x (- y 1))))))

Write a tail recursive version of this procedure.


3.) Write a tail recursive version of a procedure reverse that
takes a single parameter that is a list and returns a list with
the items in the reverse order. So

(reverse '(1 2 3))  ==> (3 2 1)
(reverse '( a (b c) d e))  ==> (e d (b c) a)


4.) Use reverse from the previous problem to help write a tail
recursive version of a procedure append which takes two arguments,
a list and an item, and returns a list with the item appended to
the end of the list.

(append '(a b c) 3)  ==> (a b c 3)
(append '(a b c) '(d e))  ==> (a b c (d e))


5.) Write a procedure called print-frame that takes two parameters,
both of them even integers. This procedure should use Scheme's display
procedure to write an "ascii-art frame" in the interactions window
consisting of two squares, one inside of the other, with the corners
of the two squares connected with diagonal lines. The dimensions of
the two squares are given by the two integer parameters. Here are a
couple of examples. The procedure call

(print-frame 20 12)

should produce the following output in the interactions window.
(Notice that these really are "squares" in that they have the same
number of characters in their horizontal and vertical sides.)

********************
**                 *
* *              * *
*  *            *  *
*   ************   *
*   *          *   *
*   *          *   *
*   *          *   *
*   *          *   *
*   *          *   *
*   *          *   *
*   *          *   *
*   *          *   *
*   *          *   *
*   *          *   *
*   ************   *
*  *            *  *
* *              * *
**                **
********************

The procedure call

(print-frame 6 24)

should produce the following output. Notice that the larger of the
two input integers should be the dimension of the outer "square".

************************
**                    **
* *                  * *
*  *                *  *
*   *              *   *
*    *            *    *
*     *          *     *
*      *        *      *
*       *      *       *
*        ******        *
*        *    *        *
*        *    *        *
*        *    *        *
*        *    *        *
*        ******        *
*       *      *       *
*      *        *      *
*     *          *     *
*    *            *    *
*   *              *   *
*  *                *  *
* *                  * *
**                    **
************************

The return value of the procedure print-frame is undefined. Implement
print-frame using tail recursive helper procedures to do the looping.