Chapter 5 Not-Really-A-Quiz
A huge idea in computational thinking is problem decomposition, in which a big problem is broken into smaller, solvable problems. The results of these smaller problems can then be used as inputs to solve the bigger problem.
Problem 5.21 reads as follows:
Write a procedure query that turns a statement into a question by swapping
the first two words and adding a question mark to the last word:
> (query '(you are experienced))
(are you experienced?)
> (query '(i should have known better))
(should i have known better?)
The solution to the problem might be described, below:
Take the original sentence and make a sentence whose contents are in the following
- Second word
- First word
- Everything but the first, second, and last words
- The last word with a question mark appended to it (eg., "better" becomes "better?"
First convert this solution description into Scheme functionality, and then
write the query function.
- Suppose that the parameter you use for query is called sent.
What combination of functions will you use to get the verb in the sentence
("are" in the first example, "should" in the second) from sent? (The
order in which you use the functions matters!) ________________________________
- What function will you use to extract the first word of sent? ________________________________
- What function will uyou use to extract the last word of sent? ________________________________
- How will you extract everything but the first two words and the last word of
- What function will allow you to attach a question mark to the last word
of sent? ________________________________
- What function will you use to put together the pieces of the sentence that
is returned by Scheme? ________________________________
- Write query.