【SICP练习】43 练习2.2
练习2.2
(define(make-segment start-point end-point)
(cons start-point end-point))
(define(start-segment seg)
(car seg))
(define(start-segment seg)
(cdr seg))
(define(make-point x y)
(cons x y))
(define(x-point p)
(car p))
(define(y-point p)
(cdr p))
(define(average x y)
(/ (+ x y) 2.0))
(define(mid-segment seg)
(let ((start (start-segment seg))
(end (end-segment seg)))
(make-point (average (x-point start)(x-point end))
(average (y-point start)(y-point end)))))
(define(print-point p)
(newline)
(display “(“)
(display (x-point p))
(display “,”)
(display (y-point p))
(display “)”))
版权声明:本文为 NoMasp柯于旺 原创文章,如需转载请联系本人。