CS 15100 Fall 2007

LectureTTh 12:00 - 1:20 Ryerson 277

ProjectsHandin by emailing to robby@cs.uchicago.edu

Project 1 due 11/6
Project 2 due 11/13
Project 3 due 11/20
Project 4 due 11/30

LabTu 4:30 - 5:50pm JRL A01C (Mac lab)

Midterm Exam10/23 4:30 - 5:50pm (during lab time) Ryerson 277

TextHow to Design Programs

Supplementary
Reading
The Little Schemer
by Freidman and Felleisen

Structure and Interpretation of Computer Programs
by Abelson and Sussman

Syllabus
WeekTopicReadings
9/25, 9/27Basic forms of dataCh 2 - 6
10/2, 10/4define-struct, unions and listsCh 6 - 10
10/9, 10/11Lists, trees, and data abstractionCh 12 - 16
10/16, 10/18Iterative refinement, 2 complex pieces of data, localCh 16 - 18
10/23, 10/25Mutually referential data defintions, abstractionCh 15, 19 - 21
10/30, 11/1abstraction, lambda, natural numbersCh 19 - 22, 24, 11
11/6, 11/8Generative recursion, graphsCh 25 - 28
11/13, 11/15Accumulators, more graphsCh 30 - 32, 14
11/20Evaluators
11/27Looking forward

Mailing ListSubscribe Archive

SoftwareDrScheme
Also installed in /opt/cs-plt/cs-plt-371 on cs machines.

Lab
Space
CS Lab

Grading
Homeworks:10%
Midterm Exam:32%
Early Labs:10%
Lab Projects:48%(handed out one 1 per lab in the last four labs)

Course
Staff
Robby Findler
Office Hours: by appt
Office: Hinds B-002

Varsha Dani
Office: Ryerson 162A

Casey Klein
Office: Ryerson 178
Office Hour: Tuesday 1:30-2:30pm

Jing Tie
Office: RI 340
Office Hour: Friday 3-4 pm

Homework
Homework is due before the beginning of class. Print it out and bring it to class. and put your name and the homework number at the top of the page.
All assignment numbers come from the online version of the text.
They may be slightly different in the first and second printing (but they match the third printing).
Due DateLanguage (in DrScheme)Problems
11/30Intermediate StudentDo not write any recursive functions for this homework.
map, filter, and foldr are built in to DrScheme.

Use map to write the next function.
;; build-straight-line : num (listof num) -> (listof posn)
;; returns a list of posns where the X coordinate is n and 
;; the Y coordinate is a number
;; in lon
;; e.g., (build-straight-line 2 (list 1 2 3)) 
;;       (list (make-posn 2 1) (make-posn 2 2) (make-posn 2 3))
(define (build-straight-line n lon) ...)

Use filter to write the next function.
;; pts-north : posn (listof posn) -> (listof posn)
;; returns the posns from lop that are north of p,
;; that is, whose y coordinate is greater than p's y coordinate
(define (pts-north p lop) ...)

Use foldr to write the next function.
;; total-width : (listof image) -> num
;; returns the sum of the widths of all images in loi
(define (total-width loi) ...)

Use map filter and foldr to write the next four functions.

The next exercises use functions to represent curves in the plane. A curve can be represented as a function that accepts an x coordinate and returns a y coordinate. For example, the straight line through the origin can be represented as
(define (diagonal x) x)
and a parabola sitting on the origin can be represented as
(define (parabola x) (* x x))
(define points (list (make-posn 1 0) (make-posn 1 1) (make-posn 2 2)))

;; points-on-line : (num -> num) (listof posn) -> (listof posn)
;; return the points in pts that are on the curve described by f
;; e.g.
;; (points-on-line diagonal points) 'shouldbe (list (make-posn 1 1) (make-posn 2 2))
;; (points-on-line parabola points) 'shouldbe (list (make-posn 1 1))
(define (points-on-line f pts) ...)

;; positions: (num -> num) (listof num) -> (listof posn)
;; returns a list of positions on the curve `f' whose x-coordinates
;; are in lon
;; e.g., (positions parabola (list 1 2 3)) 
;;       (list (make-posn 1 1) (make-posn 2 4) (make-posn 3 9))
(define (positions f lon) ...)

;; flatten-posns : (listof posn) -> (listof num)
;; constructs the list consisting of all the X and Y coordinates of each
;; of the posns in lop, in order.
;; e.g., (flatten-posns points) 'shouldbe (list 1 0 1 1 2 2)
(define (flatten-posns lop) ...)

;; possible-y-coords : (listof (num -> num)) num -> (listof num)
;; given a list of lines lof and an x-coordinate, returns the list
;; of what y-coordinate is associated with that x-coordinate in each curve
;; e.g. (possible-y-coords (list diagonal parabola) 7)
;;      (list 7 49)
(define (possible-y-coords lof x) ...)
10/18Beginning Student w/List AbbreviationsHtDP: 14.2.3, 14.2.5, 14.2.6
10/16Beginning Student w/List AbbreviationsWrite the following functions.
; a ftn is either
; - 'unknown, or
; - (make-child symbol number symbol ftn ftn)
(define-struct child (name date eyes mom dad))

; 40-year-old-ancestor? : ftn -> boolean
; to determine if a 40-year-old ancestor is in a-ftn
(define (40-year-old-ancestor? a-ftn) ...)

; count : ftn -> number
; to count the number of people in a-ftn
(define (count a-ftn) ...)

; avg-age : ftn -> number
; to determine the average age in an-ftn
(define (avg-age a-ftn) ...)
Hint: use helper functions


;; above : image image -> image
;; to put one image above another
;; HINT: use put-pinhole to move the pinhole of
;;       the first to the middle of the bottom edge
;;       and the second to the middle of the top edge
(define (above i1 i2) ...)

;; a lego is
;; - (make-lego symbol number)
(define-struct lego (color width))

;; lego->image : lego -> image
;; to render a lego brick. All legos are rectangular
;; and are 10 pixels tall
(define (lego->image l) ...)

;; a lego-building is either:
;; - lego
;; - (make-bigger lego lego-building lego-building)
(define-struct bigger (lego left right))

;; how-high : lego-building -> number
;; to determine how high a lego building is, in pixels
;; (reminder: each lego is ten pixels tall)
(define (how-high an-lb) ...)

;; find-colored-brick : lego-building color -> lego or false
;; to find any colored brick with the color `color' in an-lb
;; or return false if there are no such legos.
(define (find-colored-brick an-lb color) ...)

;; lb->image : lego-building -> image
;; to render a lego building into an image
(define (lb->image an-lb) ...)

;; Examples as tests
;; (make more tests yourself -- these should be your last tests!)

(lb->image
 (make-bigger (make-lego 'blue 100)
              (make-bigger (make-lego 'green 60)
                           (make-lego 'orange 40)
                           (make-lego 'purple 40))
              (make-bigger (make-lego 'pink 60)
                           (make-lego 'orange 40)
                           (make-lego 'purple 40))))


(lb->image
 (make-bigger (make-lego 'lightblue 80)
              (make-bigger (make-lego 'blue 40)
                           (make-bigger (make-lego 'green 20)
                                        (make-lego 'orange 10)
                                        (make-lego 'purple 10))
                           (make-bigger (make-lego 'pink 20)
                                        (make-lego 'orange 10)
                                        (make-lego 'purple 10)))
              (make-bigger (make-lego 'salmon 40)
                           (make-bigger (make-lego 'green 20)
                                        (make-lego 'orange 10)
                                        (make-lego 'purple 10))
                           (make-bigger (make-lego 'pink 20)
                                        (make-lego 'orange 10)
                                        (make-lego 'purple 10)))))
10/11Beginning Student w/List AbbreviationsUse the web-itunes teachpack for this exercise.

;; render-albums : list-of-album -> html
;; build a web page like we did in class, but include
;; all of the songs with each album, in a table inside a table.
(define (render-albums an-loa) ...)

Use this expression
(save-web-page "index.html" "Robby's Music" robbys-itunes)
to test your functions on some large inputs.
Hint: only do this when you have tested all of your functions carefully with small inputs!
10/9Beginning StudentWrite the following functions. Don't forget about re-use and helper functions (the functions we wrote in class are fair game for re-use as helper functions).

; a list-of-symbols is either
; - empty, or
; - (cons symbol list-of-symbols)

; contains-doll? : list-of-symbols -> boolean
; to determine if 'doll appears in alos
(define (contains-doll? alos) ...)

; a list-of-numbers is either
; - empty, or
; - (cons number list-of-numbers)

; len : list-of-numbers -> number
; to determine the number of elements in alon
(define (len alon) ...)

; avg : list-of-numbers -> number
; to determine the average of the elements in alon
(define (avg alon) ...)

; sq-nums : list-of-numbers -> list-of-numbers
; to square each element in alon
(define (sq-nums alon) ...)

; rev : list-of-numbers -> list-of-numbers
; to reverse the elements in alon
(define (rev alon) ...)

Images: 4.1 - 4.3
Hint: break down complex tasks into smaller ones. Wishlists!
10/4Beginning StudentHtDP: 7.2.2 (make sure all vehicles have wheels)

Develop the function toll : vehicle -> number. It determines the amount a vehicle must pay at a toll. The toll costs $0.50 per wheel.

Extend the animal data definition from class with one new kind of animal. Make sure the new animal has a weight.

Write a template for the extended animal data definition.

Write the function diet : animal -> animal. It accepts an animal and returns the same animal, but with half of the weight.
10/2Beginning StudentWrite the function direct-to-0 : posn -> number that determines how far a posn is from the origin, as the crow flies.

Write the function downtown-to-0 : posn -> number that determines how far a posn is from the origin, if the coordinates were block numbers in downtown Chicago. That is, you cannot cut through buildings and have to walk on streets (this is commonly called "Manhattan" distance, but we know better).

Write the function direct-between : posn posn -> number that determines the distance between two points, as the crow flies. (Hint: wishlists & reuse!)

Images: 2.1 - 2.3, 3.1 - 3.2
9/27Beginning StudentImages: 1.1 - 1.5