SICP 习题2.33 用accumulate完成一些基本的表操作
2016-06-24 16:05
489 查看
这个accumulate比第一章完成更强大
(define (accumulate op initial sequence) (if (null? sequence) initial (op (car sequence) (accumulate op initial (cdr sequence))))) (define (map p sequence) (accumulate (lambda (x y) (cons (p x) y)) () sequence)) (define square (lambda (x) (* x x))) (newline) (display (map square (list 1 2 3 4 5))) (define (append seq1 seq2) (accumulate cons seq2 seq1)) (newline) (display (append (list 1 2 3) (list 4 5 6))) (define (length sequence) (accumulate (lambda (x y) (+ 1 y)) 0 sequence)) (newline) (display (length (list 1 2 (list 3 4))))
相关文章推荐
- OpenCV学习笔记(2)——播放视频
- 51单片机存储器结构
- Java正则抓取Email
- c#读取xml文件
- 凸多边形的三角剖分
- android studio 解决debug adb端口问题,亲身经历总结
- Vertica 常用命令
- scrollview嵌套listview导致无法正常显示
- Jenkins自动化测试:使用临时文件实现不同测试用例间的变量传递_20160624_七侠镇莫尛貝
- python练习3——请写一个密码安全性检查的脚本代码:check.py
- MySQL行级锁SELECT FOR UPDATE 和LOCK IN SHARE MODE区别
- 1.1 Writing a Simple C++ Program
- yii 分页案例
- 玩转Eclipse开发工具(三)
- ng-style用法
- 设计模式之代理模式
- js交互
- Android横竖屏切换小结
- IOS 调取系统相册 ios9 图片模糊问题
- 深入理解SELinux SEAndroid(3最后部分)