a. If you have not done so already, please scan the corresponding reading on higher-order procedures.
b. Start DrScheme
map to compute the successors to the squares of
the integers between 1 and 10.
map to turn a list into an association list by
making each value in the first list into a a key (you can also
use the same value as the corresponding value).
map to take the last element of each list in a
list of lists. The result should be a list of the last elements.
map to sum the last elements
of each list in a list of lists of numbers. The result should be a
number. You should have written a similar procedure for
map to concisely define a
(dot-product list1 list2), that
takes as arguments two lists of numbers, equal in length, and returns
the sum of the products of corresponding elements of the arguments:
> (dot-product (list 1 2 4 8) (list 11 5 7 3)) 73 ; ... because (1 x 11) + (2 x 5) + (4 x 7) + (8 x 3) = 11 + 10 + 28 + 24 = 73 > (dot-product null null) 0 ; ... because in this case there are no products to add
Sarah and Steven Schemer suggest that ``
apply is irrelevant.
After all,'' they say, ``when you write
(apply prog (arg1 ... argn))
you're just doing the same thing as
(proc arg1 arg2 ... argn)
Given your experience in the previous exercise, are they correct? Why or why not?
a. Document and write a procedure,
that counts the number of values in list for which
b. Demonstrate the procedure by tallying the number of odd values in the list of the first twenty integers.
c. Demonstrate the procedure by tallying the number of multiples of three in the list of the first twenty integers.
Document and write a procedure,
that builds a procedure that takes a list as a parameter and tallies
the values in the list for which the predicate holds. For example
> (define count-odds (make-tallier odd?)) > (count-odds (list 1 2 3 4 5)) 3
You can assume that
tally already exists for the purpose
of this problem.
Thursday, 2 November 2000 [Samuel A. Rebelsky]
Wednesday, 14 February 2001 [Samuel A. Rebelsky]
Sunday, 8 April 2001 [Samuel A. Rebelsky]
Disclaimer: I usually create these pages on the fly. This means that they are rarely proofread and may contain bad grammar and incorrect details. It also means that I may update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.
This page was generated by Siteweaver on Thu May 3 23:07:46 2001.
This page may be found at
You may validate this page's HTML.
The source was last modified Sun Apr 8 22:06:53 2001.