hw6 - Exercise 2.74(define(get-record employee...

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

View Full Document Right Arrow Icon
;; Exercise 2.74 (define (get-record employee div-file) ((get 'get-record (type-tag div-file)) employee (contents div-file))) (define (get-salary record) (apply-generic 'salary record)) (define (find-employee-record employee divisions) (cond ((null? divisions) (error "No such employee")) ((get-record employee (car divisions))) (else (find-employee-record employee (cdr divisions))))) ; To add a new division, you must create a package for the ; division, make sure the division's personnel file is tagged ; with the division name, and add the division's file to the ; list of files used as argument to find-employee-record. ; ;; Exercise 2.75 (define (make-from-mag-ang x y) (define (dispatch op) (cond ((eq? op 'real-part) x) ((eq? op 'imag-part) y) ((eq? op 'magnitude) (* x (cos y))) ((eq? op 'angle) (* x (sin y))) (else (error "Unknown op -- MAKE-FROM-MAG-ANG" op)))) dispatch) ;; Exercise 2.76 ; Explicit Dispatch ; Need to add a dispatch for every type and operation pair ; ; Data-Directed Style ; Since this style is additive, the new set of types and its ; operations can be added seperately from others. the
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 11/30/2010 for the course EECS 21281 taught by Professor Harvey during the Spring '10 term at Berkeley.

Page1 / 4

hw6 - Exercise 2.74(define(get-record employee...

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