CS 15100 Fall 2007Lecture  TTh 12:00  1:20 Ryerson 277 
 Projects  Handin 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 
 Lab  Tu 4:30  5:50pm JRL A01C (Mac lab) 
 Midterm Exam  10/23 4:30  5:50pm (during lab time) Ryerson 277 
 Text  How to Design Programs 
 Supplementary Reading  The Little Schemer by Freidman and Felleisen
Structure and Interpretation of Computer Programs by Abelson and Sussman 
 Syllabus  Week  Topic  Readings  9/25, 9/27  Basic forms of data  Ch 2  6  10/2, 10/4  definestruct, unions and lists  Ch 6  10  10/9, 10/11  Lists, trees, and data abstraction  Ch 12  16  10/16, 10/18  Iterative refinement, 2 complex pieces of data, local  Ch 16  18  10/23, 10/25  Mutually referential data defintions, abstraction  Ch 15, 19  21  10/30, 11/1  abstraction, lambda, natural numbers  Ch 19  22, 24, 11  11/6, 11/8  Generative recursion, graphs  Ch 25  28  11/13, 11/15  Accumulators, more graphs  Ch 30  32, 14  11/20  Evaluators   11/27  Looking forward  

 Mailing List  Subscribe Archive 
 Software  DrScheme Also installed in /opt/csplt/csplt371 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 B002
Varsha Dani Office: Ryerson 162A
Casey Klein Office: Ryerson 178 Office Hour: Tuesday 1:302:30pm
Jing Tie Office: RI 340 Office Hour: Friday 34 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 Date  Language (in DrScheme)  Problems 

11/30  Intermediate Student  Do not write any recursive functions for this homework. map, filter, and foldr are built in to DrScheme.
Use map to write the next function.;; buildstraightline : 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., (buildstraightline 2 (list 1 2 3))
;; (list (makeposn 2 1) (makeposn 2 2) (makeposn 2 3))
(define (buildstraightline n lon) ...)
Use filter to write the next function.;; ptsnorth : 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 (ptsnorth p lop) ...)
Use foldr to write the next function.;; totalwidth : (listof image) > num
;; returns the sum of the widths of all images in loi
(define (totalwidth 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 (makeposn 1 0) (makeposn 1 1) (makeposn 2 2)))
;; pointsonline : (num > num) (listof posn) > (listof posn)
;; return the points in pts that are on the curve described by f
;; e.g.
;; (pointsonline diagonal points) 'shouldbe (list (makeposn 1 1) (makeposn 2 2))
;; (pointsonline parabola points) 'shouldbe (list (makeposn 1 1))
(define (pointsonline f pts) ...)
;; positions: (num > num) (listof num) > (listof posn)
;; returns a list of positions on the curve `f' whose xcoordinates
;; are in lon
;; e.g., (positions parabola (list 1 2 3))
;; (list (makeposn 1 1) (makeposn 2 4) (makeposn 3 9))
(define (positions f lon) ...)
;; flattenposns : (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., (flattenposns points) 'shouldbe (list 1 0 1 1 2 2)
(define (flattenposns lop) ...)
;; possibleycoords : (listof (num > num)) num > (listof num)
;; given a list of lines lof and an xcoordinate, returns the list
;; of what ycoordinate is associated with that xcoordinate in each curve
;; e.g. (possibleycoords (list diagonal parabola) 7)
;; (list 7 49)
(define (possibleycoords lof x) ...)
 10/18  Beginning Student w/List Abbreviations  HtDP: 14.2.3, 14.2.5, 14.2.6  10/16  Beginning Student w/List Abbreviations  Write the following functions. ; a ftn is either ;  'unknown, or ;  (makechild symbol number symbol ftn ftn) (definestruct child (name date eyes mom dad))
; 40yearoldancestor? : ftn > boolean ; to determine if a 40yearold ancestor is in aftn (define (40yearoldancestor? aftn) ...)
; count : ftn > number ; to count the number of people in aftn (define (count aftn) ...)
; avgage : ftn > number ; to determine the average age in anftn (define (avgage aftn) ...) Hint: use helper functions
;; above : image image > image ;; to put one image above another ;; HINT: use putpinhole 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 ;;  (makelego symbol number) (definestruct 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 legobuilding is either: ;;  lego ;;  (makebigger lego legobuilding legobuilding) (definestruct bigger (lego left right))
;; howhigh : legobuilding > number ;; to determine how high a lego building is, in pixels ;; (reminder: each lego is ten pixels tall) (define (howhigh anlb) ...)
;; findcoloredbrick : legobuilding color > lego or false ;; to find any colored brick with the color `color' in anlb ;; or return false if there are no such legos. (define (findcoloredbrick anlb color) ...)
;; lb>image : legobuilding > image ;; to render a lego building into an image (define (lb>image anlb) ...)
;; Examples as tests ;; (make more tests yourself  these should be your last tests!)
(lb>image (makebigger (makelego 'blue 100) (makebigger (makelego 'green 60) (makelego 'orange 40) (makelego 'purple 40)) (makebigger (makelego 'pink 60) (makelego 'orange 40) (makelego 'purple 40))))
(lb>image (makebigger (makelego 'lightblue 80) (makebigger (makelego 'blue 40) (makebigger (makelego 'green 20) (makelego 'orange 10) (makelego 'purple 10)) (makebigger (makelego 'pink 20) (makelego 'orange 10) (makelego 'purple 10))) (makebigger (makelego 'salmon 40) (makebigger (makelego 'green 20) (makelego 'orange 10) (makelego 'purple 10)) (makebigger (makelego 'pink 20) (makelego 'orange 10) (makelego 'purple 10)))))
 10/11  Beginning Student w/List Abbreviations  Use the webitunes teachpack for this exercise.
;; renderalbums : listofalbum > 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 (renderalbums anloa) ...)
Use this expression (savewebpage "index.html" "Robby's Music" robbysitunes) 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/9  Beginning Student  Write the following functions. Don't forget about reuse and helper functions (the functions we wrote in class are fair game for reuse as helper functions).
; a listofsymbols is either ;  empty, or ;  (cons symbol listofsymbols)
; containsdoll? : listofsymbols > boolean ; to determine if 'doll appears in alos (define (containsdoll? alos) ...)
; a listofnumbers is either ;  empty, or ;  (cons number listofnumbers)
; len : listofnumbers > number ; to determine the number of elements in alon (define (len alon) ...)
; avg : listofnumbers > number ; to determine the average of the elements in alon (define (avg alon) ...)
; sqnums : listofnumbers > listofnumbers ; to square each element in alon (define (sqnums alon) ...)
; rev : listofnumbers > listofnumbers ; to reverse the elements in alon (define (rev alon) ...)
Images: 4.1  4.3 Hint: break down complex tasks into smaller ones. Wishlists!
 10/4  Beginning Student  HtDP: 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/2  Beginning Student  Write the function directto0 : posn > number that determines how far a posn is from the origin, as the crow flies.
Write the function downtownto0 : 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 directbetween : 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/27  Beginning Student  Images: 1.1  1.5 

