CS 119 Lab 3 – Higher-Order Procedures
Objectives
Perform the following tasks in the order given.
(every first ‘(american civil liberties union))
(every abs ‘(-2 4 –5 –3 0))
You can also use a word as the second argument. In this case, the first argument function is applied to every letter in the word. The results are collected in a sentence. Try
(every (lambda(wd)(se (word ‘with wd) ‘you)) ‘(in out))
| Assignment: Use every to write a procedure exaggerate which exaggerates sentences in the following way: Þ
(exaggerate ‘(i ate 3 hotdogs)) Þ
(exaggerate ‘(this is a good time)) The function doubles all the numbers in the sentence and it replaces "good" with "great", and replaces "bad" with "terrible". Hint: The function applied to each word in the sentence should check for the special cases and return the appropriate results. Otherwise, it should just return the word unchanged. |
| Assignment: Use keep to write a procedure first-last which returns a sentence containing only those words in the argument whose first and last letters are the same:
|
| Assignment: Use accumulate to hyphenate a sentence of words together:
Hint: Remember that the function given to accumulate must take two words and combine them. |
| Assignment: Write a function acronym using only every, keep, and accumulate which behaves as follows:
Note that the small connecting words "and" and "of" are not part of the acronym. You may use the predicate real-word? in lab3.scm to determine which words are not irrelevant. |