SICP Exercise 2.74 Insatiable Enterprises
Exercise 2.74. Insatiable Enterprises, Inc., is a highly decentralized conglomerate company consisting of a large number of independent divisions located all over the world. The company's computer facilities have just been interconnected by means of a clever network-interfacing scheme that makes the entire network appear to any user to be a single computer. Insatiable's president, in her first attempt to exploit the ability of the network to extract administrative information from division files, is dismayed to discover that, although all the division files have been implemented as data structures in Scheme, the particular data structure used varies from division to division. A meeting of division managers is hastily called to search for a strategy to integrate the files that will satisfy headquarters' needs while preserving the existing autonomy of the divisions.
Show how such a strategy can be implemented with data-directed programming. As an example, suppose that each division's personnel records consist of a single file, which contains a set of records keyed on employees' names. The structure of the set varies from division to division. Furthermore, each employee's record is itself a set (structured differently from division to division) that contains information keyed under identifiers such as address and salary. In particular:
a. Implement for headquarters a get-record procedure that retrieves a specified employee's record from a specified personnel file. The procedure should be applicable to any division's file. Explain how the individual divisions' files should be structured. In particular, what type information must be supplied?
b. Implement for headquarters a get-salary procedure that returns the salary information from a given employee's record from any division's personnel file. How should the record be structured in order to make this operation work?
c. Implement for headquarters a find-employee-record procedure. This should search all the divisions' files for the record of a given employee and return the record. Assume that this procedure takes as arguments an employee's name and a list of all the divisions' files.
d. When Insatiable takes over a new company, what changes must be made in order to incorporate the new personnel information into the central system?
Show how such a strategy can be implemented with data-directed programming. As an example, suppose that each division's personnel records consist of a single file, which contains a set of records keyed on employees' names. The structure of the set varies from division to division. Furthermore, each employee's record is itself a set (structured differently from division to division) that contains information keyed under identifiers such as address and salary. In particular:
a. Implement for headquarters a get-record procedure that retrieves a specified employee's record from a specified personnel file. The procedure should be applicable to any division's file. Explain how the individual divisions' files should be structured. In particular, what type information must be supplied?
b. Implement for headquarters a get-salary procedure that returns the salary information from a given employee's record from any division's personnel file. How should the record be structured in order to make this operation work?
c. Implement for headquarters a find-employee-record procedure. This should search all the divisions' files for the record of a given employee and return the record. Assume that this procedure takes as arguments an employee's name and a list of all the divisions' files.
d. When Insatiable takes over a new company, what changes must be made in order to incorporate the new personnel information into the central system?
Logical Structure of a division file:
Division ID: 12345
Division Name: 'Insatiable Bengaluru'
Employee Records:
Ravi Varma: '123 Mariamman Kovil St., Nungambakkam, Chennai - 600045', 'Rs. 100000 per month'
Susheel Javadi: '234 5th Cross, Malleshwaram, Bengaluru - 560050', 'Rs. 150000 per month'
Brahma Joshi: '345 Pusa Road, New Delhi - 100046', 'Rs. 50000 per month'
Sitara Shanbag: '456 Udupi Road, Tirthahalli - 740082', 'Rs. 175000 per month'
Example 1 Implementation of a division file:
(list
"Division File"
(list "Division ID" 1)
(list "Division Name" "Insatiable Bengaluru")
(list
"Employee Records"
(list "Employee Record" (list "Employee ID" 3456) (list 'Name "Ravi Varma") (list 'Address "123 Mariamman Kovil St., Nungambakkam, Chennai - 600045") (list 'Salary "Rs. 100000 per month"))
(list "Employee Record" (list "Employee ID" 3457) (list 'Name "Susheel Javadi") (list 'Address "234 5th Cross, Malleshwaram, Bengaluru - 560050") (list 'Salary "Rs. 150000 per month"))
(list "Employee Record" (list "Employee ID" 3458) (list 'Name "Brahma Joshi") (list 'Address "345 Pusa Road, New Delhi - 100046") (list 'Salary "Rs. 50000 per month"))
(list "Employee Record" (list "Employee ID" 3459) (list 'Name "Sitara Shanbag") (list 'Address "456 Udupi Road, Tirthahalli - 740082") (list 'Salary "Rs. 175000 per month"))
)
)
Example 2 Implementation of a division file:
(list
"Division File"
(cons "Division ID" 2)
(cons "Division Name" "Insatiable America")
(list
"Employee Records"
(list 3459 "Pavni Duggal" "123 Hana Road, Edison NJ - 08817" "$10000 per month")
(list 3460 "Bhuvan Seth" "3421 Bloomfield Hills, Scranton, MA - 52846" "$5000 per month")
(list 3461 "Sameer Jois" "49 Crooked Street, San Diego, CA - 95862" "$1000 per month")
)
)
and so on...
; Op Table Structure
; When new divisions are added, we need to add new rows to this table. That is better than
; adding new columns, hence this choice of structure
| get-record get-salary get-name get-address
------------------------------------------------------------------------------------------------
Division 1 | get-record-div1 get-salary-div1 get-name-div1 get-address-div1
Division 2 | get-record-div2 get-salary-div2 get-name-div2 get-address-div2
etc.
.
.
------------------------------------------------------------------------------------------------
Comments
Post a Comment