Fundamentals of CS I (CS151 2001S)
[Current]
[Discussions]
[Glance]
[Honesty]
[Instructions]
[Links]
[News]
[Search]
[Syllabus]
Primary
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Quizzes]
[Readings]
[Reference]
Sets
[Blackboard]
[Scheme Report]
[SamR's Schedule]
[Rebelsky/Fall 2000]
[Walker/Fall2000]
[Stone/Spring2000]
Links
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.
c. Tell DrScheme not to print the lengths of vectors by entering
(print-vector-length #f)
.
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 by entering
(print-vector-length #t)
.
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 procedure, (vector-sum numbers)
,
that takes one argument, a vector
of numbers, and returns the sum of the elements of that vector.
You can
use vector->list
from the reading as a pattern for
vector-sum
-- only a few judicious changes are needed.
However, you should not use vector->list
as a helper.
Write a Scheme procedure,
(length-of-every-element strings
,
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)
In the reading on vectors, we saw
that it was possible to implement list->vector
and
vector->list
by using more primitive operations
(particularly vector-set!
and vector-length
).
Write your own version of vector-fill!
. Remember that
vector-fill!
takes two parameters, a vector and a
value, and puts that value in every position of the vector.
Just as in the case of list->vector
, you will probably
want to define a helper procedure that fills only part of the vector.
Your termination condition will certainly be different and should probably
involve the length of the vector.
Wednesday, 20 September 2000
Wednesday, 8 November 2000
http://www.cs.grinnell.edu/~stone/courses/scheme/vectors.xhtml
(version of April 5, 2000).
http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2000F//Labs/vectors.html
Wednesday, 7 February 2001
Thursday, 8 February 2001
vector->list
should be used as a pattern rather
than as a helper.
http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2001S//Labs/vectors.html
[Current]
[Discussions]
[Glance]
[Honesty]
[Instructions]
[Links]
[News]
[Search]
[Syllabus]
Primary
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Quizzes]
[Readings]
[Reference]
Sets
[Blackboard]
[Scheme Report]
[SamR's Schedule]
[Rebelsky/Fall 2000]
[Walker/Fall2000]
[Stone/Spring2000]
Links
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:08:08 2001.
This page may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2001S/vectors.html
.
You may validate
this page's HTML.
The source was last modified Thu Mar 8 09:42:07 2001.