sicp 2.3

Exercise 2.3.  Implement a representation for rectangles in a plane. (Hint: You may want to make use of exercise 2.2.) In terms of your constructors and selectors, create procedures that compute the perimeter and the area of a given rectangle. Now implement a different representation for rectangles. Can you design your system with suitable abstraction barriers, so that the same perimeter and area procedures will work using either representation?

 

假设矩形的边平行于坐标轴,使用对角线上的两点构造矩形,即可

你可能感兴趣的:(SICP)