EBoard 25: Vectors (Section 2)
Warning! You are being recorded and transcribed, provided the technology
is working correctly.
Approximate optimistic overview
- Administrative stuff
- About MP7
- Q&A (not on Vectors)
- Notes and questions on Vectors
Administrative stuff
Introductory notes
- I have not yet had time to get the quizzes graded. They should be graded
and available on Gradescope by Saturday night. I’ll bring the hardcopies
on Monday.
- I overslept this morning, so some links are missing from the eboard. I’ll
add them after class.
- If you sent me a recent email or TM asking for an extension, I may have
missed it. Please Teams Message me again.
Upcoming activities
Scholarly
- Thursday, 10 April 2025, 11am–noon, HSSC A1231.
Scholars’ Convocation: Jen Shook: Instead of RedFace: Relational Trails in “Indian Country,” Onstage, Online, and IRL
- Thursday, 10 April 2025, 4:00–5:30pm, the Kernel (HSSC Multipurpose Room).
CS Poster Session
- Tuesday, 15 April 2025, noon–1pm, Some PDR.
CS Table: ???
Artistic
- Friday, 4 April 2025 5:00–7:00 p.m., Saturday, 5 April 2025, 1:00–4:00 p.m.,
and Sunday, 6 April 2025, 1:00–4:00 p.m.
Educational Comics Workshop.
- You must attend all three sessions.
- But you’ll earn three tokens.
- Sunday, 6 April 2025 2:00 p.m. Sebring-Lewis.
Grinnell Singers
Multicultural
- Friday, 4 April 2025, 4:00–5:00 p.m., HSSC N1170 (Global Living Room).
Middle of Everywhere: Vietnam
- Friday, 4 April 2025, 6:00–9:00 p.m.,. JRC 101.
Eid Fest
- Saturday, 5 April 2025, 5:30–7:00 p.m., HSSC Atrium.
Slavic Coffee House.
- Friday, 11 April 2025, 4:00–5:00 p.m., HSSC N1170 (Global Living Room).
_Middle of Everywhere:???
Peer
Musical, theatric, sporting, and academic events involving this section’s
students are welcome.
- Read articles by your fellow CSC-151 students and comment on them online.
- Saturday, 5 April 2025, Noon, Baseball field.
Baseball vs. Monmouth.
- Saturday, 5 April 2025, 2:30 p.m., Baseball field.
Baseball vs. Monmouth.
- Sunday, 6 April 2025, Noon, Baseball field.
Baseball vs. Monmouth.
Wellness
- Friday, 4 April 2025, 6:00 p.m.–8:00 p.m., Aux Gym.
Badminton Club (Smash that bird!)
- Friday, 4 April 2025, 9:00 p.m., Noyce Elbow.
Nerf at Noyce.
- Saturday, 5 April 2025, 4:00 p.m.–6:00 p.m., Aux Gym.
Badminton Club (Smash that bird!)
- Tuesday, 8 April 2025, 12:15–12:50 p.m., GCMoA.
Yoga in the Museum.
- Tuesday, 8 April 2025, 4:30–6:30 p.m.,
BRAC P103 (Multipurpose Dance Studio).
Wellness Yoga.
- Thursday, 10 April 2025. ???. ???.
Forest Bathing.
- Tuesday, 15 April 2025, 5:00–6:00 p.m., HSSC Atrium.
Therapy Dogs.
- Tuesday, 15 April 2025, 7:15–8:15 p.m., HSSC Atrium.
Therapy Dogs.
Misc
- Friday, 4 April 2025, 3:00–5:00 p.m., Burling Digital Studio.
GCIEL / Digital Studio Workshop: Spatial Audio and Immersive Soundscapes
- Sunday, 6 April 2025, 7:30–8:30 p.m., Science 3819.
Mentor Session
- Tuesday, 8 April 2025, 7:00–8:00 p.m., Science 3820.
Mentor Session
- Wednesday, 9 April 2025, Noon–1:00 p.m., HSSC A2231 (Auditorium)
Community Forum
- “Weekly discussion on legal protections and recourse on issues
that higher education and Grinnell College face.”
- Also online.
- This week: Karen Edwards on Immigration Regulations.
Other good things
These do not earn tokens, but are worth your consideration.
- Lots of softball games this weekend.
Upcoming work
- Friday, 4 April 2025
- Sunday, 6 April 2025
- Monday, 7 April 2025
- Tuesday, 8 April 2025
- Submit lab writeup for Class 26 on Gradescope
- Readings
- Randomness
- Submit reading response on randomness on Gradescope
- Wednesday, 9 April 2025
- Quiz: Diagramming structures (paper only)
- Makeup quiz: List recursion
- Makeup quiz: Tracing
- Thursday, 10 April 2025
- Friday, 11 April 2025
- Sunday, 13 April 2025
- Monday, 14 April 2025
Friday PSA
- You’re awesome. Please try to remain that way.
- Please be moderate in what you do. Cake to excess is bad.
- Consent is essential but not sufficient.
Mini-Project 7
- Key idea: Play with an underlying representation of images.
- Part one: Explore rows and columns.
- Part two: Using the idea to make a variant of images.
- Part three: More variants.
- Part four: Steganography.
- Part five: Freestyle.
- You only need to do one of parts three and four for an M.
Questions
Questions
Administrative
Mini-project 6
For some of my fractals, it said my images didn’t look correct. What should
I do?
Option 1: Fingers crossed.
Option 2: Ask Sam via Teams Message.
Other
Vectors
TPS
What is a vector?
- It’s like a list. That is, it represents a sequence of values.
- Unlike lists, you change them.
What are the key vector operations?
(vector-set! vec index new-value)
- Puts the new value at the given
position. (We don’t know of a list equivalent.)
(make-vector length val)
- Makes a vector of the given length containing
that many copies of the value. (Similar operation for lists: make-list
).
(vector val0 ...)
- Makes a vector containing those values. (Similar
operation for lists: list
.)
(vector-length vec)
- Tells you the length of the vector (size, number
of elements in the vector). (Similar operation for lists: length
.)
(vector-ref vec pos)
- Extract an element from the vector. (For
lists, we have list-ref
).
What are the three key C list operations?
(cons val lst)
- Creates a new list by adding an element to the
front of lst
. We did not learn an equivalent operation for vectors
(there isn’t really one). Vectors have a fixed length.
(car lst)
- Returns the element at index 0. We use vector-ref
to achieve a similar goal.
(cdr lst)
- Returns a “new” list without the first element of lst
.
Sam did not teach us a similar vector operation (because there isn’t
really one).
What distinguishes vectors from lists?
- Unlike lists, you change vectors.
- Unlike lists, vectors have a fixed length.
- It’s much faster to find the
i
th element of a vector than a list.
- For a list, we need to cdr through the list
i
times and then
call car
.
- For a vector, we can quickly compute a new memory location.
Why would you use one rather than the other?
- If you’re going to be doing lots of indexing (not in sequential order),
vectors are much better.
- If you’re going to be adding and removing elements, you probably want
to use a list.
- If you’re going to be changing elements, you should use vector.
How does vector-set!
differ from other procedures we’ve seen?
- It doesn’t return anything.
- It changes one of its parameters.
(define tn3 (vector-set! (vector-set! (make-vector 2 0) 0 7) 1 11))
- The inner
vector-set!
returns nothing, and so the outer vector-set!
doesn’t have a vector to modify.
- If you don’t name the vector and use vector-set!, the vector is lost!
Programming with vectors
How might programming with vectors differ from the other kinds of
programming we’ve done? (Think especially about recursive programming
and vector-set!
.)
- Historically, we have sequenced operations by nesting.
(proc3 (proc2 (proc1 vall)))
.
- Since
vector-set!
doesn’t return anything, we must sequence by
writing things one after another.
-
(vector-set! vec 0 "zero")
(vector-set! vec 1 "one")
Some exercises
;;; (vector-tally-odd vec) -> integer?
;;; vec : (vector-of exact-integer?)
;;; Count how many odd numbers are in the vector.
(define vector-tally-odd
(lambda (vec)
(vector-tally-odd-helper vec 0)))
;;; (vector-tally-odd-helper vec index) -> integer?
;;; vec : (vector-of exact-integer?)
;;; index : exact-integer? (between 0 and (vector-length vec))
;;; Tally the odd element in vector starting at the given index.
- We’ll need to use
vector-ref
to get elements out of the vector.
- We’ll need to index to run from 0 (inclusive) to
(vector-length vec)
(exclusive)
- If we need to keep track of the index, we’ll need a helper procedure.
- We’re going to need to use recursion.
- Base case test: Index is greater than or equal to length vector
- Base case value: 0
- Recursive call
- Pre-recursion or post-recursion step
(define vector-tally-odd-helper
(lambda (vec index)
(if (>= index (vector-length vec))
0
(+ (if (odd? (vector-ref vec index))
1
0)
(vector-tally-odd-helper vec (+ 1 index))))))
;;; (vector-increment-odd! vec) -> void
;;; vec : (vector-of exact-integer?)
;;; Add one to all the odd numbers in the vector.
Q&A (from reading and elsewhere)
Can we go over how to make tn3
?
Sure.
Why is tn1
immutable?
Rules of Scheme: If you make a vector with the octothorpe, you get an immutable vector.
In our first self-check, tn1
, tn2
, and tn3
all contain the same
elements. Why is tn1
not equal to tn2
or tn3
?
tn1
is immutable. tn2
and tn3
are mutable. Immutable and mutable
structures are not equal.
What is the ‘file’ type referred to in the reading? Are we talking about an actual .rkt file here?
Whoops. Sometimes we cover how to build text and data files in the course. We didn’t this semester.
I don’t think I’m clear on what you mean by “DrRacket displaying the value of the vector” in Check 1. Does that just mean the result of calling tn1
, tn2
, etc?
Yes, displaying the value in a vector is just what you get when you type the identifier.