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)))
比较简单,直接上代码(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)))
相关文章推荐
- 指针的内容 ; 指针的地址 指针所指向的内容 指针的类型 指针所指向的类型
- POJ 1125 Stockbroker Grapevine
- poj 1837 Balance
- Android的banner(轮播图)的实现
- 两端输出字符,从两端移动向中间汇聚; 模拟三次密码输入
- 获取select option自定义元素的值
- 关于自己
- 在 MFC 框架中,有什么方法能直接将 OpenCV 2.0 库中 Mat 格式的图片传递到 Picture Control(图片控件)显示?
- BNUOJ-20950-沉重的货物(最小生成树的Prim算法)
- 百钱买百鸡最优解
- CodeForces 628B New Skateboard
- Python enumerate
- 位段那些事
- CodeForces 628A Tennis Tournament
- C++第五次上机实验
- Charset.defaultCharset() 获取的语言环境的编码到底是哪里来的 ?
- go mobile 得生命周期事件
- poj之旅——2393
- c语言题中的一些陷阱
- IIstesbuS.90