Outline 37: Pairs and Pair Structures
Held: Monday, 11 April 2016
Back to Outline 36 - Randomized (Unpredictable) Drawing.
On to Outline 38 - Vectors.
Summary
We consider pairs, the basic data type used to build
lists and other structures in Scheme. We also consider why it
is useful to understand about pairs.
Related Pages
Overview
- Representing lists: Pairs and cons cells.
- Why care about the underlying representation?
Administrivia
- Continue partners (since I said you could continue Friday's lab)
- I will continue to bring you food (or food-like substances) until I am
caught up on grading.
- You will need at least one sheet of paper today. Grab one from the
back of the room.
- I have not had the opportunity to read much email today. If you sent
a question, I'll get to it early this evening.
- We'll have a little time at the start of class for you to work on
Friday's lab. (Please start on today's lab at 3:25 p.m.)
Reminders
- Office hours this week
- See http://rebelsky.youcanbook.me.
- Ask me about other available times.
- Tutor hours
- Sunday, 3-5 p.m.
- Sunday-Thursday, 7-10 p.m.
- Review Sessions
- Wednesday at 8pm in CS commons with Sarah (?)
- Thursday at 8pm in CS commons with ????
- None with Sam this week
Upcoming Work:
- Reading for Tuesday:
- Lab Writeup:
- Hand me a piece of paper with the answers.
- Due before class on Tuesday.
Extra Credit
- Send your reports to rebelsky@grinnell.edu with subject
"CSC 151 Extra Credit". (Do not include the quotation marks.)
- Send opportunities to me before class with subject
"CSC 151 EXTRA CREDIT OPPORTUNITY!"
Academic / Artistic
- Talk today, 4pm, ARH 302
- Talk Wednesday, 4pm, ARH 302
- Talk Thursday, 4pm, place TBD
- Any of the fora on "Thrive Not Survie" this or next week.
Peer
- Lords of the Flies, 7:30 pm April 22nd, 2:00 pm April 23rd, 2:00 9pm April 24th. (Only 50-60 tickets per show)
- Bollywood "Bhangra" Dance in ISO, Saturday, April 16, 7-9pm
Miscellaneous
- Host a prospective student this coming weekend.
Regular Peer
- Social Dance Workshop Tuesdays 7:00-8:00 in Bucksbaum Dance Studio
- Post-break ExCo on British Politics Wednesdays at 8:00 in JRC 203.
Just show up; you don't need to sign up.
- Pun club Saturdays at 4pm in Younker
- Electronic Potpourri on KDIC Fridays at Five
- Space Odyssey KDIC Fridays at Six
- Bollywood, Fridays, 7:30-8:30, Younker
- Effective Altruism club, 2:30-3:30 Sundays in JRC 226.
Misc
Far in the Future
- Adaptation of Rushdie's East West. Early May.
Questions
I'm having trouble with postconditions for rac and rcd.
For rdc, you can talk about the length of the list and the value
at each position.
For rac, you can probably rely on list-ref to clarify the
postcondition.
Can we use position-distance in solving the stenciled circle problem?
Yes.
Can we text you with questions tonight?
Yes. But before 10 p.m. (You can email after 10 p.m.; the odds are
that I'll still be awake.)
Are there positive aspects to your failure to grade exam 2 in a timely fashion?
Yes. I am much less likely to take off for formatting and insufficient examples on exam 3.
What should index-of-substring return if there are multiple matching positions?
Any of those positions (usually the first).
Any hints on finding the errors?
Be thorough. If it were me, I'd try more substring sizes and more
substring positions.
Cons Cells
- One set of interesting values in Scheme are the things that
cons
creates. We often call these cons cells or pairs
- The first value of a pair is a reference to the first parameter to cons.
The second value is a reference to the second parameter.
- I'll also draw some pictures of these things in class.
Dotted Pairs
- Although we've used lists as the second parts of each cons cell, you
can use other values. If the second part of a cons cell is not a list,
you get what is called a dotted pair.
- The shorthand for a dotted pair is
'(x . y).
- You'll also see the dot at the end of a long sequence of cons cells.
- Why is the dot there?
- To distinguish things close to lists from lists.
- Why is it right before the last element, and not earlier?
- Because we don't know until we hit the end that it's not a list.
Why Care?
- Why should we care about the underlying structure used for lists?
- Because it helps explain why Scheme does some things the way it does.
- Because it helps us understand the hidden costs associated with some operations.
- Because it helps us better understand recursion over lists.
- Because it provides background for future discussions.
Lab
- Any preliminary questions?
- Do the labthe lab.
- Be prepared to reflect.