[Current] [News] [Glance] [Discussions] [Instructions] [Search] [Links] [Handouts] [Outlines] [Readings] [Labs] [Homeworks] [Quizzes] [Exams] [Examples] [Fall2000.01] [Spring2000]

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
`vector`

procedure.

c. Create a vector that contains the same two values by using the
`make-vector`

and `vector-set`

procedures.

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.
the result

- #4(0)
- #4(1)
- #4(1 2)
- #2(1 2 3 4)
- (make-vector 4 0)

c. Tell DrScheme not to print the lengths of vectors and reenter each expression. Do your results differ? What do the differences suggest?

Write a `vector-sum`

procedure that takes one argument, a vector
of numbers, and returns the sum of the elements of that vector. (You can
use `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
those strings.

>(length-of-every-element '#("red" "white" "and" "blue"))#(3 5 3 4)

Consider the three versions of the `double-every-element`

procedure from reading on vectors.

Which version of `double-every-element`

do you prefer?
Why?

Let's generalize the `length-of-every-element`

procedure
you've just written and the `double-every-element`

procedure
from reading on vectors.

Write a `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).

Extend your `vector-map`

so that it accepts an arbitrary number
of vectors as parameters.

Wednesday, 20 September 2000

- Started.

Wednesday, 8 November 2000

- Finished.
- Exercises 0, 1, 3, and 4 are based on John Stone's and Henry
Walker's Vectors lab, which may be found at
`http://www.cs.grinnell.edu/~stone/courses/scheme/vectors.xhtml`

(version of April 5, 2000). - Exercises 2, 5, 6, and 7 are new.

[Current] [News] [Glance] [Discussions] [Instructions] [Search] [Links] [Handouts] [Outlines] [Readings] [Labs] [Homeworks] [Quizzes] [Exams] [Examples] [Fall2000.01] [Spring2000]

**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 rebelsky@grinnell.edu