Skip to main content

CSC 151.01, Class 37: Pairs and Pair Structures

Overview

  • Preliminaries
    • Notes and news
    • Welcome prospective students!
    • Upcoming work
    • Extra credit
    • Discussion of homework 7
    • Questions
  • Representing lists with pairs and cons cells
  • Why care about the underlying representation
  • Other pair structures
  • Lab

News / Etc.

  • New partners!
  • Congratulations to 1st-year-mentor and her team for third 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?
  • E: Colby, Macalester, Oberlin ; What are your majors? What is CS/math like here?
    • Come to Grinnell because we won’t criticize that which we do not know.
    • Math is joyfully challenging here.
    • CS has joyous amounts of math and even more joyous amounts of application. Math is pretty.
  • A: U. of Tulsa, Kenyon, UC Berkeley. What do you wish you’d known when you arrived at Grinnell?
    • Wow, Berkeley is nice. Go there. But Grinnell is pretty close knit, so we’re good too. Plus you drink the Grinnell “water” and magically become really nice.
    • Portable water purifiers are not that expensive.
  • M: Miami of the wrong state or Grinnell. What’s stage tech like?
    • We have both student productions and faculty-led productions (and guest directed productions). You can get credit. You need not be a Theatre and Dance major to participate. Justin Thomas is the bomb.
    • We don’t have grad students. (People at Miami of Ohio are confused as to where they are so they are less nice.) We have lots of money and will fund things. We’ll even pay to stable horses for the equestrian club or buy flaming clubs for juggling. We fund externships that send you all around to visit alums. Costume makers, coders, NPR radio directors, entrepreneurs, ethical metalsmiths.
    • We have awesome alums (they drank the “water”)
  • T: Macalester and Occidental. What languages do we use?
    • Scheme, C, Java, ML, Ruby, and more as appropriate
    • Random students lead classes. For example, some students are running a Python class. Oter students started an AppDev club.
    • I don’t know about the other schools, but we’re awesome. Plus, Mac is in a city and Occidental is in a bigger city. We’re in the middle of beautiful prairie (well, we were, but burned
  • Lawrence, Kenyon, Dennison. What is something you like about Grinnell?
    • All are awesome schools. Choose the one that feels best to you.
    • Grinnell lets you do things that other places won’t let you do. Play Cricket, sing A Capella, Drink Chai on Fridays.a Amazing experience.
    • We give you nice financial aid packages. (Well, maybe not you, but lots of awesome students.)
    • It’s not Chicago. The water is much worse here.
    • Close-knit community. it down on Friday night)

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.
  • Baseball vs. Knox Saturday noon or 2:30 p.m.
  • Drag show Saturday night.

Extra credit (Misc)

  • Watch Kington attempt to dive today at 4:30 p.m.

Other good things to do

None right now

Discussion of HW7

For problem 2, we’ll think about how to do the square image.

In English, how do I draw a square of side length len, given that all I know is how to move my pen forward and turn?

square of length len
repeat 4 times
  forward len
  turn 90

How would we translate that to Scheme?

(define turtle-square!
  (lambda (turtle len)
    (repeat 4 (lambda ()
                (turtle-forward! turtle len)
                (turtle-turn! turtle 90)))))

vs.

(define turtle-square!
  (lambda (turtle len)
    (repeat 4 (lambda (t)
                (turtle-forward! t len)
                (turtle-turn! t 90))
               turtle)))

vs.

(define turtle-square!
  (lambda (turtle len)
    (repeat 4 (lambda (t l a)
                (turtle-forward! t l)
                (turtle-turn! t a))
               turtle
               len
               90)))

All of these are acceptable. The model is (repeat TIMES PROCEDURE ARGS)

Now, suppose I wanted to draw a square at each corner of that square. How would my English instructions change?

nested square of length len
repeat 4 times
  forward len
  draw a square of length .4 * len
  turn 90

How about our Scheme instructions?

(define turtle-nested-square!
  (lambda (turtle len)
    (repeat 4 (lambda ()
                (turtle-forward! turtle len)
                (turtle-square! turtle (* .4 len))
                (turtle-turn! turtle 90)))))

Can we improve this?

We might turn -90 instead of 90 when doing the recursive drawing.

What if we wanted to include the number of levels?

(define turtle-squareflake!
  (lambda (turtle len levels)
    (when (> levels 0)
      (repeat 4 (lambda ()
                  (turtle-forward! turtle len)
                  (turtle-squareflake! turtle (* .4 len) (- levels 1))
                  (turtle-turn! turtle 90))))))

For problem 3, you should either clone the turtle or move the turtle back to where it was before drawing the next branch. (Please don’t teleport turtles; it’s a non-sustainable practice.)

Questions

Lab