a. If you have not done so already (or if you've forgotten what it says), please reread the reading on vectors.
b. Start DrScheme and tell it not to print the lengths of vectors.
a. In DrScheme's interaction window, type in a vector literal that denotes a vector containing just the two elements 3.14159 and 2.71828. How does DrScheme display the value of this vector?
b. Create a vector that contains the same two values by using the
c. Create a vector that contains the same two values by using the
a. Tell DrScheme to print the length of vectors.
b. Enter each of the following vector expressions in DrScheme; consider
the result (perhaps by examining individual elements with
vector-ref); and indicate what vector has been created.
c. Tell DrScheme not to print the lengths of vectors and reenter each expression. Do your results differ? What do the differences suggest?
vector-sum procedure that takes one argument, a vector
of numbers, and returns the sum of the elements of that vector. (You can
our-vector->list as a pattern for
vector-sum -- only a few judicious changes are needed.)
Write a Scheme procedure
length-of-every-element that takes as
argument a vector of strings and returns a vector containing the lengths of
> (length-of-every-element '#("red" "white" "and" "blue")) #(3 5 3 4)
Consider the three versions of the
procedure from reading on vectors.
Which version of
double-every-element do you prefer?
Let's generalize the
you've just written and the
from reading on vectors.
vector-map procedure that takes two arguments, a
procedure and a vector, and creates a new vector that contains the result
of applying the procedure to each element of the vector, in turn.
As you may recall, the built-in
map procedure accepts two
or more parameters. If there are additional parameters, it
requires that the remaining parameters by lists and creates element
i of the result list by applying the procedure to element i of each
source list (where i is a number between 0 and length-1, inclusive).
vector-map so that it accepts an arbitrary number
of vectors as parameters.
Wednesday, 20 September 2000
Wednesday, 8 November 2000
(version of April 5, 2000).
Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.
This page may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2000F/Labs/vectors.html
Source text last modified Wed Nov 8 10:16:29 2000.
This page generated on Wed Nov 8 10:21:13 2000 by Siteweaver. Validate this page's HTML.
Contact our webmaster at email@example.com