欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

SICP 2.3 习题答案

程序员文章站 2022-07-14 10:56:07
...
可能书上想让我用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)))
相关标签: Scheme