Held: Monday, 9 November 2015
Back to Outline 37 - Pairs and Pair Structures.
On to Outline 39 - Pause for Breath.
Summary
We consider vectors, an alternative to lists for storing collections
of data.
Related Pages
Overview
- Problems with lists.
- A solution: Vectors.
- Behind the scenes: How Scheme implements vectors.
- Important vector procedures.
Administrivia
- New partners!
- Review sessions this week:
- Monday, 8pm (Zachary)
- Wednesday, 8pm (Caleb)
- Thursday, 10am (SamR)
- Thursday, 8pm (Erin)
- Office hours this week and next: MWF 8:30-9:00, 11:00-11:45, 1:00-2:00;
Tu 1:00-2:00.
- Tuesday's reading is not yet ready. Expect it this afternoon.
Upcoming Work
Extra Credit Opportunities
- If possible, send me these in advance.
Academic
- Any visit to the current show in the Faulconer gallery.
- Learning Deconstructed Workshop Series, Tuesdays at 11 in JRC 209.
- CS Table Tuesday: Cryptographic Back Doors.
- Wilson talk Wednesday: Startup (in)Sanity. 7:30 p.m., ARH 102.
- CS Extras Thursday: Developing and Deploying Mobile Sensing Applications.
Peer Support
- Orchestra Concert, November 14, Sebring Lewis, 7:30 p.m.
- Women's Basketball Opening Game, 1 pm, Nov. 15, vs. Silver Lake.
- ISO Food Bazaar. Nov. 15, 5-7 pm, Harris Gym/Concert Hall.
- Alumni Game for Womens Basketball 1pm on Saturday.
Regular Peer Support
- Pals of PALS, pals@grinnell.edu, normally Saturday at 7:45 am (breakfast
included; felines only), and Mondays at 4:45. Requires sign up in
advance. MORE HELP NEEDED!
- Socrates Cafe', Saturdays, Younker, 2pm.
- Pun Club, Saturdays, 4pm, Way over Younker.
Upcoming Peer Support
- Tranaslations (a play). Nov 19-23 or so.
- One-act Festival Dec. 5 & 6.
Data Types
- At the start of the semester, we decided that "basic values and
operations on those values" are key to writing algorithms.
- We tend to use the word "type" to express these two concepts.
- We've seen a variety of characteristics of types in 151.
- Some types are defined in terms of a list of possible values or a simple construction method: Character, Boolean, RGB color, etc.
- Some types that can potentially be defined recursively: Drawings-as-value,
Maybe integers, Lists.
- Some types are designed to collect other kinds of values: Lists. (Okay, maybe that's it for now.)
- We're about to learn a few more. Vectors today. Pair structures (particularly trees) on Monday.
List Deficiencies
- Now that we've worked with lists for a while, we've identified
some things that make lists inappropriate for some situations.
- List are expensive to use; to find the length of a list
or to access an element late in the list, you need to cdr down the
list.
- Lists are fixed; you can't easily change an element of a
list.
- At the same time, there are some advantages to lists:
- Lists are dynamic; it is easy to grow and shrink a list.
- Lists are inherently recursive; the type is defined
recursively.
- Lists are simple; you can build almost every list operation
through just a few basic operations (
car, cdr,
null, and null?).
An Alternative: Vectors
- Vectors provide an alternative to lists.
- They have two primary advantages:
- Vectors are indexed: You can quickly access elements by number.
- Vectors are mutable: You can change the elements of a vector.
- In order to obtain these benefits, vectors lack some key features of lists. In particular,
- Vectors are static: Once you've created a vector, you cannot change its length.
- Some key vector procedures:
(vector val1 ... valn): Create a vector
(make-vector length val): Make a vector of specified length, with duplicates of val as the contents.
(vector-ref vector position): Extract a value from a vector.
(vector-set! vector position newvalue): Change an element of a vector.
(vector-length vector)
Implementing Vectors
- To be done live in class: Memory layout and more.
Lab