SICP 2.2 习题答案
程序员文章站
2022-07-14 10:55:07
...
cons对于数据结构来说是一个很强大的东西
(define (print-point p) (newline) (display "(") (display (x-point p)) (display ",") (display (y-point p)) (display ")")) (define (make-point x y) (cons x y)) (define (x-point p) (car p)) (define (y-point p) (cdr p)) (define (make-segment start end) (cons start end)) (define (start-segment segment) (car segment)) (define (end-segment segment) (cdr segment)) (define (midpoint-segment segment) (cons (/ (+ (x-point (start-segment segment)) (x-point (end-segment segment))) 2) (/ (+ (y-point (start-segment segment)) (y-point (end-segment segment))) 2))) (define p1 (make-point 1 2)) (define p2 (make-point 1 4)) (define s (make-segment p1 p2)) (x-point p1) (y-point p1) (print-point p1) (print-point (midpoint-segment s))
上一篇: hive日期函数 整理
下一篇: 锂电池与镍镉电池有什么区别