首页 > 其他分享 >sicp每日一题[2.74]

sicp每日一题[2.74]

时间:2024-11-11 19:45:03浏览次数:1  
标签:files division name get 每日 sicp 2.74 record employee

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?


a. 这道题里,部门名称就相当于前面所说的类型,获取部门信息就是操作,我们根据这两个信息从提前建好的二维表里提取雇员所属部门的文件。每个部门文件都应该有一个 get-division 的过程,它根据雇员姓名获取对应的部门文件。

(define (get-record get-division employee-name) 
   ((get 'division get-division) employee-name)) 

b. 这道题跟上一题很像,只是这次是从某个雇员的记录中获取工资信息。

(define (get-salary get-division record) 
  ((get 'salary get-division) record)) 

c. 这道题就是依次检查所有部门,根据雇员名称获取记录。

(define (find-employee-record employee-name division-list) 
  (if (null? division-list) 
      #f 
      (or (get-record (car division-list) employee-name) 
          (find-employee-record employee-name (cdr division-list))))) 

d. 每次接管一个新公司,都要把上述提到的过程添加到二维表里,使用的时候根据部门类型和操作来获取对应公司的过程。

标签:files,division,name,get,每日,sicp,2.74,record,employee
From: https://www.cnblogs.com/think2times/p/18540416

相关文章

  • 每日模版 | 专升本毕业论文(工商管理)开题
    加文末微信,获取论文服务:......
  • 每日一题之二叉树
    已知结点元素值为正整数且值不相同的一棵二叉树。该二叉树通过给出其先序遍历序列和中序遍历序列构造而成。输入一个整数x,针对此二叉树编写程序求出x的右子树中所有结点值的和(若x不在树上,输出-1)。 输入说明:第一行输入某二叉树的先序遍历序列第二行输入该二叉树的中序遍历......
  • 蓝桥杯每日真题 - 第7天
    题目:(爬山)题目描述(X届C&C++B组X题)解题思路:前缀和构造:为了高效地计算子数组的和,我们可以先构造前缀和数组a,其中a[i]表示从第1个元素到第i个元素的和。这样,对于任意区间[i,j]的子数组和,可以通过a[j]-a[i-1]快速得到。枚举所有区间和:用双重循环枚举所有可......
  • 每日一题.设计相邻元素求和服务;暴力算法与哈希表的运用
    本题出自LeetCode每日一题3242,可以说比昨天的那道“每日抑题”简单不少呀,就是代码长一点,同时本题目使用了两种不同的方法,并对每一种用法进行了深度解析。本文全长5000字。题目 给你一个 nxn 的二维数组 grid,它包含范围 [0,n2-1] 内的不重复元素。实现 neighbo......
  • sicp每日一题[2.73]
    最近状态不太好,再加上2.73前面的内容有点多,学的有点吃力,所以昨天就没做。。Exercise2.73Section2.3.2describedaprogramthatperformssymbolicdifferentiation:(define(derivexpvar)(cond((number?exp)0)((variable?exp)(if(same-va......
  • 每日OJ题_牛客_BC157素数回文_数学_C++_Java
    目录牛客_BC157素数回文_数学题目解析C++代码Java代码牛客_BC157素数回文_数学素数回文_牛客题霸_牛客网描述:现在给出一个素数,这个素数满足两点:1、  只由1-9组成,并且每个数只出现一次,如13,23,1289。2、  位数从高到低为递减或递增,如2459,87631。请你判断一下,这......
  • GitHub每日最火火火项目(11.7)
    项目名称:DataExpert-io/data-engineer-handbook项目介绍:“DataExpert-io/data-engineer-handbook”是一个非常有价值的资源库。这个项目收集了与数据工程相关的各种学习链接,涵盖了数据工程领域的方方面面。对于想要深入了解数据工程的人来说,它就像是一个知识宝库。无论是......
  • Leetcode 每日一题 135.分发糖果
    问题描述给定一个整数数组ratings,表示一排孩子的评分。我们需要按照以下规则给孩子们分发糖果:每个孩子至少得到1个糖果。相邻两个孩子中,评分更高的孩子会得到更多的糖果。我们的目标是计算出按照这些规则分发糖果所需的最少糖果数。输入输出格式输入:一个整数数组 rating......
  • 高级java每日一道面试题-2024年10月29日-JVM篇-简述分代垃圾回收器是怎么工作的?
    如果有遗漏,评论区告诉我进行补充面试官:简述分代垃圾回收器是怎么工作的?我回答:在Java高级面试中,分代垃圾回收器的工作原理是一个重要的考点。下面将详细解释分代垃圾回收器是如何工作的:分代垃圾回收器的基本概念分代垃圾回收器是一种基于对象生命周期的垃圾回收方......
  • 高级java每日一道面试题-2024年10月28日-RabbitMQ篇-RabbitMQ的使用场景有哪些?
    如果有遗漏,评论区告诉我进行补充面试官:RabbitMQ的使用场景有哪些?我回答:RabbitMQ是一个开源的消息代理和队列服务器,它遵循高级消息队列协议(AMQP)。RabbitMQ的核心作用是作为应用程序之间的中介,实现异步消息传递。它可以帮助解耦系统组件、提供消息的持久化、支持消息......