您的位置:首页 > 其它

SICP(1985) ex2-2 line-segment

2016-05-11 12:47 417 查看
要求创建一个数据类型线段,能够给出线段中点

比较简单,直接上代码(define (make-line-segment start-point end-point)
(cons start-point end-point))
(define (make-point coordinatex coordinatey)
(cons coordinatex coordinatey))
(define (coordinatex x) (car x))
(define (coordinatey x) (cdr x))
(define (start-point line) (car line))
(define (end-point line) (cdr line))
(define (get-midpoint line)
(cons (/ (+ (coordinatex (start-point line)) (coordinatex (end-point line))) 2) (/ (+ (coordinatey (start-point line)) (coordinatey (end-point line))) 2)))

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: