Skip to main content

Class 37: Pairs and Pair Structures

Held:

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.*

Preliminaries

Overview

  • Representing lists with pairs and cons cells
  • Why care about the underlying representation
  • Other pair structures

Updates

News / Etc.

  • New partners!
  • Congratulations to HR and her team for first place in Pioneer Weekend!
  • Congratulations to our Singers for a spectacular Saturday concert.
  • Congratulations to our Disco Trumpeter for what I hear was a great concert.
  • I’ll be returning exam 2 later today and distributing current grades tonight.

Prospective Students

  • What is you name?
  • Where else are you considering?
  • What question do you have for these students?

Upcoming Work

  • Lab writeup: TBD.
  • Reading for Tuesday: Vectors
  • HW7 is due Tuesday night!

Extra credit (Academic/Artistic)

  • CS Table, Tuesday, noon, Technical Interviews
  • CS Extras, Thursday, 4:15 pm, Ursula Wolz on High School Coding Conferenc3
  • The Barber of Seville, Monday, 17 April 2017, 7:30 p.m., Herrick
  • Spark Tank Pitch Contest, Thursday, 11am-1pm, Harris
  • James McBride and the Good Lord Bird Band, Thursday, 8pm, Herrick

Extra credit (Peer)

  • Submit to (or attend) the Art House Arts Fest on April 22nd. They want visual art, performance art, musical talent, crafting skills, culinary arts etc. If anyone is interested in participating they can email our Art House member.
  • After spending this entire weekend doing Improv at a conference, Ritalin Test Squad will be doing 24 Hour Improv the upcoming Friday. They will be performing in Loose Lounge from 6pm Friday to 6pm Saturday. There may be other improv troupes performing with them.
    • Get sleep! Do not attend for all 24 hours.
  • Basseball vs. Knox Saturday at noon or 2:30 p.m.

Extra credit (Misc)

Other good things to do

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.