Exercise 1.43

If f is a numerical function and n is a positive integer, then we can form the nth repeated application of f, which is defined to be the function whose value at x is f (f (...(f (x)). . .)). For example, if f is the function x -> x + 1, then the nth repeated application of f is the function x -> x + n. If f is the operation of squaring a number, then the nth repeated application of f is the function that raises its argument to the 2^n-th power. Write a procedure that takes as inputs a procedure that computes f and a positive integer n and returns the procedure that computes the nth repeated application of f. Your procedure should be able to be used as follows:

((repeated square 2) 5)
625

Hint: You may find it convenient to use compose from Exercise 1.42.


这道题稍微复杂一点,要用一个循环来实现重复调用目标函数 n 次。

; f 表示函数,参数只有一个且为数值;n 表示要嵌套执行多少次 f 函数
(define (repeated f n)
(if (= n 1)
(lambda (x) (f x))
(compose f (repeated f (- n 1))))) ((repeated square 2) 5)
((repeated inc 10) 5) ; 执行结果
625
15

sicp每日一题[1.43]的更多相关文章

  1. 老男孩IT教育-每日一题汇总

    老男孩IT教育-每日一题汇总 第几天 第几周 日期 快速访问链接 第123天 第二十五周 2017年8月25日 出现Swap file….already exists以下错误如何解决? 第122天 2 ...

  2. 【Java每日一题】20170106

    20170105问题解析请点击今日问题下方的"[Java每日一题]20170106"查看(问题解析在公众号首发,公众号ID:weknow619) package Jan2017; ...

  3. 【Java每日一题】20170105

    20170104问题解析请点击今日问题下方的"[Java每日一题]20170105"查看(问题解析在公众号首发,公众号ID:weknow619) package Jan2017; ...

  4. 【Java每日一题】20170104

    20170103问题解析请点击今日问题下方的"[Java每日一题]20170104"查看(问题解析在公众号首发,公众号ID:weknow619) package Jan2017; ...

  5. 【Java每日一题】20170103

    20161230问题解析请点击今日问题下方的"[Java每日一题]20170103"查看(问题解析在公众号首发,公众号ID:weknow619) package Jan2017; ...

  6. 【Java每日一题】20161230

    // 20161229问题解析请点击今日问题下方的"[Java每日一题]20161230"查看(问题解析在公众号首发,公众号ID:weknow619)package Dec2016 ...

  7. 【Java每日一题】20161229

    package Dec2016; import java.util.ArrayList; import java.util.List; public class Ques1229 { public s ...

  8. 【Java每日一题】20161228

    package Dec2016; import java.util.ArrayList; import java.util.List; public class Ques1228 { public s ...

  9. 【Java每日一题】20161227

    package Dec2016; public class Ques1227 { public static void main(String[] args){ } { c = 1; } int c ...

  10. 【Java每日一题】20161226

    package Dec2016; public class Ques1226 { static{ num = 1; } public static int num = 2; public static ...

随机推荐

  1. Python入门学习介绍

    什么是Python? Python它是一种直译式,面向对象,解释式的脚本语言.它和Java,C/C++,Go语言一样都是高级语言,但由于它是解释式语言,所以运行速度会比Java,C/C++等语言慢(虽 ...

  2. Python爬虫(1-4)-基本概念、六个读取方法、下载(源代码、图片、视频 )、user-agent反爬

    Python爬虫 一.爬虫相关概念介绍 1.什么是互联网爬虫 如果我们把互联网比作一张大的蜘蛛网,那一台计算机上的数据便是蜘蛛网上的一个猎物,而爬虫程序就是一只小蜘蛛,沿着蜘蛛网抓取自己想要的数据 解 ...

  3. 可视化—gojs 超多超实用经验分享(四)

    目录 41.监听连线拖拽结束后的事件 42.监听画布的修改事件 43.监听节点被 del 删除后回调事件(用于实现调用接口做一些真实的删除操作) 44.监听节点鼠标移入移出事件,hover 后显示特定 ...

  4. Django model层之执行原始SQL查询

    Django model层之执行原始SQL查询 by:授客 QQ:1033553122 测试环境 Win7 Django 1.11   执行原始SQL查询 Manager.raw(raw_query, ...

  5. 【VUE】el-menu导航菜单过长、过多 超出窗口宽度 添加左右滚动按钮实现左右滚动效果

    本文为原创文章,转载需注明出处~~ 效果图: 项目需求:如果一级菜单过多,需要出现滚动点击按钮. 准备工作:考虑到使用swiper插件,但swiper-slider必须是swiper-wrapper的 ...

  6. .NET周刊【7月第4期 2024-07-28】

    国内文章 .NET 高性能缓冲队列实现 BufferQueue https://mp.weixin.qq.com/s/fUhJpyPqwcmb3whuV3CDyg BufferQueue 是一个用 . ...

  7. Android 性能稳定性测试工具 mobileperf 开源 (天猫精灵 Android 性能测试-线下篇)

    Android 性能稳定性测试工具 mobileperf 开源 (天猫精灵 Android 性能测试-线下篇) 这篇文章写得很好!感谢阿里云开发者社区!!! 原文地址: https://develop ...

  8. 【Excel】VBA编程 02 访问MySQL数据库

    1.配置Windows连接驱动ODBC 因为是访问MySQL,则对应的ODBC驱动由MySQL厂商发布 https://dev.mysql.com/downloads/connector/odbc/ ...

  9. 【Redis】01 NoSQL概述 & Redis

    NoSQL概述: 1.什么是NoSQL NoSQL 是 Not Only SQL 的缩写,意即"不仅仅是SQL"的意思,泛指非关系型的数据库.强调Key-Value Stores和 ...

  10. 进程的CPU绑定是否有意义 —— 进程的 CPU 亲和性

    好多年前就学习过 进程的 CPU 亲和性这个概念,说直白些就是CPU的进程绑定,也就是指定某个进程绑定到某个CPU核心上,以此提高进程切换时缓存的命中率,加快进程的运算速度. 虽然在编程的时候中会遇到 ...