CS 119 Lab 2 – Recursion
Objectives
Perform the following tasks in the order given.
1. Evaluate the files words.scm, quilting.scm, and lab2.scm. In the file lab2.scm, look at the two recursive functions reverse1 and reverse2 which both take a word as argument and return the word with the letters in reverse order. We will examine these functions with a useful debugging tool called trace.
Enter the command:
(trace reverse1)
Now, when we invoke the function reverse1, an Inspector window comes up which shows you each time the function was called. You can use the Value button to see what value each function call returned. The indentation shows the level of recursion. Try this out with reverse1.
Notice in the definition of reverse2, the trace is already placed inside. This is because we are probably interested in tracing reverse-helper, rather than reverse2. Try typing (trace reverse-helper) at the scheme prompt and see what happens. Why did that happen?
Now try using the function reverse2. Notice how the recursion differs from the recursion of reverse1.
|
Assignment: |
2. Look at the function downup. We want this function to behave as follows:
Þ
(downup ‘cake)
(cake ake ke e ke ake cake)
Þ
(downup ‘a)
(a)
If you try this however, you will notice that there is a mistake in the definition of downup.
|
Assignment: |
3. We want a function explode which behaves as follows:
Þ
(explode ‘dynamite)
(d y n a m i t e)
The function takes a word as its argument and returns the sentence containing the single letters of this word.
|
Assignment: |
4. Section 2.4 in your text describes custom-sized quilts. Take the file containing your previously defined quilt functions and extend it as follows:
|
Assignment: |
5. Email your files containing the assignments to jzimmerm@goucher.edu.