SICP Exercise 2.74 Insatiable Enterprises a, b, c & d
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.
SOLUTION
The code and tests are here.
Notes: As we can see, the procedure get-record works on any division's file. The structure of the individual divisions' files is not of consequence. What matters is the presence of division-level procedures that fetch the fields of interest. These procedures are then placed in the operation table that is indexed at run-time to find the procedure that will work for a particular division
The 'type' information to be supplied is 'get-record i.e. the implementation of the headquarter-level get-record procedure should indicate to the generic get proc that it is interested in the get-record procedure for a particular division
The structure of an employee record is not important. This is because this is hidden behind the implementation of 'get-salary' at the division level. And the generic procedure is able to find the correct get-salary procedure by indexing into the operation table
When Insatiable takes over a new company the changes are all additive:
1. The new company's divisions will implement the same procedures registered in the operation table above.
2. The operation table maintainer will add new rows (one per division) to it to register the new procedures. Everything will work after these changes
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?
SOLUTION
The code and tests are here.
Notes: As we can see, the procedure get-record works on any division's file. The structure of the individual divisions' files is not of consequence. What matters is the presence of division-level procedures that fetch the fields of interest. These procedures are then placed in the operation table that is indexed at run-time to find the procedure that will work for a particular division
The 'type' information to be supplied is 'get-record i.e. the implementation of the headquarter-level get-record procedure should indicate to the generic get proc that it is interested in the get-record procedure for a particular division
The structure of an employee record is not important. This is because this is hidden behind the implementation of 'get-salary' at the division level. And the generic procedure is able to find the correct get-salary procedure by indexing into the operation table
When Insatiable takes over a new company the changes are all additive:
1. The new company's divisions will implement the same procedures registered in the operation table above.
2. The operation table maintainer will add new rows (one per division) to it to register the new procedures. Everything will work after these changes
Comments
Post a Comment