week3b_sol - 1 CS61A Notes 06 Data-Directed...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CS61A Notes 06 – Data-Directed Programming (with some Scheme-1) [Solutions v1.0] Data-Directed Programming QUESTION: The TAs have broken out in a cold war; apparently, at the last midterm-grading session, someone ate the last potsticker and refused to admit it. It is near the end of the semester, and Professor Harvey really needs to enter the grades. Unfortunately, the TAs represent the grades of their students differently, and refuse to change their representation to someone else’s. Professor Harvey is far too busy to work with five different sets of procedures and five sets of student data, so for educational purposes, you have been tasked to solve this problem for him. The TAs have agreed to type-tag each student record with their first name, conforming to the following standard: (define type-tag car) (define content cdr) It’s up to you to combine their representations into a single interface for Professor Harvey to use. 1. Write a procedure, (make-tagged-record ta-name record) , that takes in a TA’s student record, and type-tags it so it’s consistent with the type-tag and content accessor procedures defined above. (define make-tagged-record cons) Why not list? 2. A student record consists of two things: a “name” item and a “grade” item. Each TA represents a student record differently. Min uses a list, whose first element is a name item, and the second element the grade item. Justin uses a cons pair, whose car is the name item, and the cdr the grade item. Make calls to put and get , and write generic get-name and get-grade procedures that take in a tagged student record and return the name or grade items, respectively. (put ‘Min ‘get-name car) (put ‘Min ‘get-grade cadr) (put ‘Justin ‘get-name car) (put ‘Justin ‘get-grade cdr) (define (get-name tagged-record) ((get (type-tag tagged-record) ‘get-name) (content tagged-record))) (define (get-grade tagged-record)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/14/2010 for the course EECS 61A taught by Professor Harvey during the Summer '08 term at Berkeley.

Page1 / 4

week3b_sol - 1 CS61A Notes 06 Data-Directed...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online