6.001 SICP Spring 2004 2/23/2004

Tutorial 3

Topics

Data Abstraction, Higher-Order Procedures

Upcoming Deadlines

• Problem set 3 due Tuesday, 2/24 at midnight

• Lecture 7 due Wednesday, 2/25 at 9am

• Lecture 8 due Friday, 2/27 at 9am

• Project 2 due Friday, 2/27 at 6pm

Data Abstraction and Higher-Order Procedures - Fantasy NCAA hoops

(define (make-player name team position)
  (list name team position))
(define (make-stats player points rebounds assists)
  (list player points rebounds assists))
(define (make-fantasy proc-pts proc-rebs proc-asts)
  (lambda (s)
    (+ QUESTION-1 QUESTION-2 QUESTION-3)))
; Accessors
(define player-name QUESTION-4)
(define player-team QUESTION-5)
(define player-position QUESTION-6)
(define get-player QUESTION-7)
(define get-points QUESTION-8)
(define get-rebounds QUESTION-9)
(define get-assists QUESTION-10)

; Create a few players:
(define channing-frye (make-player "Channning Frye" "Arizona" "center"))
(define frye-stats (make-stats channing-frye 18 13 1))
(define salim-stoudamire (make-player "Salim Stoudamire" "Arizona" "guard"))
(define stoudamire-stats (make-stats salim-stoudamire 12 2 3))
(define craig-smith (make-player "Craig Smith" "Boston College" "forward"))
(define smith-stats (make-stats craig-smith 11 6 2))
; Create our fantasy point system:
; Every 5 points is one fantasy point
(define (point-pts points)
  QUESTION-11)
; Every 2 rebounds is one fantasy point
(define (rebound-pts rebounds)
  QUESTION-12)
; Every assist is one fantasy point
(define (assist-pts assists)
  QUESTION-13)
; Define our fantasy system
(define fantasy
  QUESTION-14)
; Create a fantasy team from a list of players:
(define my-team (list frye-stats stoudamire-stats smith-stats))
; Compute fantasy points for the entire team
(define (team-pts team fantasy)
  QUESTION-16)
; Get all guards on the team
(define (get-guards team)
  QUESTION-17)