可能书上想让我用2.2的答案,实在不想那么搞。。。
(define (make-point x y) (cons x y))
(define (x-point p) (car p))
(define (y-point p) (cdr p))
(define (make-rect left-top right-bottom) (cons left-top right-bottom))
(define (bottom-left rect)
(make-point (x-point (car rect))
(y-point (cdr rect))))
(define (bottom-right rect) (cdr rect))
(define (top-left rect) (car rect))
(define (top-right rect)
(make-point (x-point (cdr rect))
(y-point (car rect))))
(define (width-rect rect)
(abs (- (x-point (car rect)) (x-point (cdr rect)))))
(define (height-rect rect)
(abs (- (y-point (car rect)) (y-point (cdr rect)))))
(define (perimeter-rect rect)
(* 2 (+ (width-rect rect) (height-rect rect))))
(define (area-rect rect)
(* (width-rect rect) (height-rect rect)))