`
frenchmay
  • 浏览: 231342 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

SICP Exercise 1.32-1.33

 
阅读更多
(define (accumulate combiner null-value term a next b)
  (if (> a b)
      null-value
      (combiner (term a )
        (accumulate combiner null-value term (next a) next b)
        )
      )
  )

(define (accumulate-iter combiner null-value term a next b)
  (define (iter null-value a b)
    (if (> a b)
        null-value
        (iter (combiner null-value (term a)) (next a) b)
        )
    )
  (iter null-value a b)
  )

(define (inc n) (+ n 1))  
   
(define (cube a) (* a a a))

(define (sum term a next b)  
  (accumulate + 0 term a next b)
  )
(define (sum-iter term a next b)  
  (accumulate-iter + 0 term a next b)
  )

(define (sum-cubes a b)    
  (sum cube a inc b)
  )  
(define (sum-cubes-iter a b)    
  (sum-iter cube a inc b)
  )  

(sum-cubes 1 10) 
(sum-cubes-iter 1 10) 
 


(define (filtered-accumulate combainer filter? null-value term a next b)
(if (> a b)
null-value
(if (filter? a)
(combainer (term a) (filtered-accumulate combainer filter? null-value term (next a) next b))
(filtered-accumulate combainer filter? null-value term (next a) next b)
)
)
)

(define (isok a) (= a a))

(define (sum-filtered-accumulate term a next b)
(filtered-accumulate + isok 0 term a next b)
)

(define (sum-filtered-accumulate-cubes a b)
(sum-filtered-accumulate cube a inc b)
)
(sum-filtered-accumulate-cubes 1 10)
 
分享到:
评论

相关推荐

    sicp-py-zh:[译] UCB CS61a SICP Python 描述 中文版

    docker run -tid -p <port>:80 apachecn0/sicp-py-zh # 访问 http://localhost:{port} 查看文档 PYPI pip install sicp-py-zh sicp-py-zh # 访问 http://localhost:{port} 查看文档 NPM npm install -g sicp-py-zh ...

    sicp-in-python(中文版+英文版)PD

    sicp-in-python(中文版+英文版)PDF 背景. SICP 全称Structure and Interpretation of Computer Programs,翻译过来叫《计算机程序的构造和解释》使用python

    Python库 | sicp-0.0.2-py3-none-any.whl

    资源分类:Python库 所属语言:Python 资源全名:sicp-0.0.2-py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059

    sicp-js-zh:【译】NUS CS1101s SICP JavaScript 描述

    NUS CS1101s SICP JavaScript 描述原文:协议:如果你交给某人一个程序,你将折磨他一整天;如果你教某人如何编写程序,你将折磨他一辈子。...下载Dockerdocker pull apachecn0/sicp-js-zhdocker run -tid

    CeO2对SiCp/Al-Si复合材料组织及性能的影响 (2015年)

    采用粉末冶金法制备 SiCp/Al-Si复合材料,以 CeO2 为变质剂,制备含 CeO2 的 SiCp/Al-Si 复合材料。研究 CeO2 的添加量(质量分数)对复合材料组织和力学性能的影响,探讨复合材料中 CeO2 在烧结过程中的作用机理。研究...

    激光表面熔覆SiCp/Ni-Cr-B-Si-C涂层的组织演化及其相确定

    运用激光熔覆技术在AISI1045钢表面制备了30vol-% SiCp/Ni-Cr-B-Si-C涂层。SEM和TEM观察分析表明:SiCp在熔覆过程中完全溶解;涂层结合区组织为共晶结构;涂层组织由初生石墨球G,分布在γ-Ni固溶体枝晶中的M23(C,B)6...

    sicp-study-group:一个研究计算机程序结构和解释(SICP)的研究小组

    这个“sicp-study-group”项目显然是一个围绕该书的学习社区,旨在深入探讨编程语言、计算理论以及程序设计的原理。 SICP的核心主题是解释器的构建,它不仅涵盖了编程语言的基础,还深入到函数式编程、抽象数据类型...

    SiCp/Al-Fe-V-Si复合材料组织与性能的热稳定性 (2008年)

    为研究SiCP/Al-Fe-V-Si复合材料的热稳定性,对多层喷射沉积技术制备的SiC颗粒增强Al-Fe-V-Si合金经过不同温度下的热稳定性实验后进行了硬度检测,并对其显微组织进行了电镜观察。结果表明:随着基体合金材料中Fe含量的...

    sicp-eg-ex:sicp课程视频示例,自己的笔记,习题题解

    本文将围绕"Sicp-eg-ex"这个项目,结合标题和描述,探讨在学习SICP过程中遇到的例子、笔记和习题解,特别是环境检查方案9.5的相关知识点。 首先,我们关注到的是"SICP课程视频示例"。SICP课程的核心在于通过实际的...

    sicp-compiler-notes:有关SICP编译器的一些说明和演示

    在SICP上进行试用-> WASM编译演示:SICP如何将机器代码注册为WASM 为阶乘翻译LISP代码(define (factorial n) (define (iter product counter) (if (> counter n) product (iter (* counter product) (+ counter 1)))...

    sicp-py-zh:【译】UCB CS61a SICP Python

    压缩包中的"sicp-py-zh-master"很可能包含了整个项目的源代码、翻译后的文本、示例程序、测试以及其他相关资源。以下是对SICP Python中核心知识点的详细解释: 1. **函数式编程**: - **高阶函数**:函数可以作为...

    不同冷却条件SiCp/ZA-27复合材料界面的TEM观察 (2001年)

    主要用透射电子显微技术(TEM)、电子探针显微分析(EPMA)和选区电子衍射技术(SAD)分析了不同冷却条件下SiCp/ZA-27复合材料的界面特征和结构,发现冷却速度明显影响复合材料的界面结构、界面相组成和复杂金属氧化物的...

    喷射沉积SiCP/Al-Si复合材料干滑动磨损性能的研究 (2013年)

    采用喷射沉积法制备SiCP体积分数为15%,Si质量分数分别为7%,13%和20%的SiCP/Al-Si复合材料,并经热挤压致密化加工.采用环块式摩擦试验机对复合材料的干滑动摩擦磨损性能进行了测试分析,滑动速度为1 m/s,外加载荷...

    sicp-study-group

    CoRecursive Slack SICP研究小组 章节 1-1-1 ::表达式 1-1-2 ::命名与环境 1-1-3 ::评估组合 1-1-4 ::复合程序 1-1-5 ::程序应用的替代模型 1-1-6 ::条件表达式和谓词 1-1-7 ::例子:牛顿法求平方根 1-1-8 :...

    sicp-memo-ans:SICP笔记和答案

    sicp备忘录 包含 SICP 每个部分的注释和答案。 请参考那些正在学习SICP的人。 笔记 如果你想在 gauch 中使用随机函数 (use math.mt-random) (define m (make <mersenne> :seed (sys-time))) (mt-random-integer m ...

    sicp-to-z80:一台SICP寄存器机到TI-84 Z80编译器

    最终目标是完全支持SICP指令集,然后使用此编译器将Scheme编译为Z80,或直接将Scheme编写为Z80。 无论哪种方式,该项目对我来说也意味着可以在TI-84(不是最好的语言)上探索Z80装配中的编程。特征显示字符串和数字...

    sicp in python 中文 sicp 中文

    sicp in python 中文版 sicp in python 中文版 sicp in python 中文版 !!!download>>>https://github.com/wizardforcel/sicp-py-zh

    sicp in python 中文版 sicp

    sicp in python 中文版 sicp in python 中文版 sicp in python 中文版 download : https://github.com/wizardforcel/sicp-py-zh

Global site tag (gtag.js) - Google Analytics