2.74 Exercise 2.74
This exercise is powered by Magical Thinking(TM). It also needs to be finished.
We assume that lookup procedures are stored in a ’lookup table keyed by the division names.
(define (get-record division name) ((get 'lookup division) name))
We choose to pass a record to get-salary to avoid coupling with get-record.
(define (get-salary division employee-record) ((get 'salary division) employee-record))
We assume that the lookup procedures return nil if a record can’t be found, and use flatmap to get rid of them, leaving only a valid record if one exists.
(define (find-employee-record divisions name) (flatmap (lambda (d) (get-record d name)) divisions))
If Insatiable takes over a new company, they have a few options for integrating their separate employee records systems. One is to add another layer of indirection by creating a new table keyed by the company. For example:
(define (get-record company division name) (((get 'get company) 'lookup division) name))
This is less invasive than possibly modifying the names of the divisions to avoid collisions.
Looking up get is not the only thing we could do – we could write a new version of get that takes the company and the division and handles a second layer of lookups itself. Writing a more generic version of get, instead of having procedures tied directly to tables (as I assume is the case now), has benefits of its own. But at this point, we’re reinventing databases.