P29 (**) Compose arbitrarily many procedures of one argument.
来源:互联网 发布:域名续费怎么收费 编辑:程序博客网 时间:2024/04/26 04:52
问题描述
原题目没有P29,这道题来源于水木的一个帖子。题目是这样的:
Use the unrestricted lambda to define a composition procedure compose-many
that forms the composition of arbitrarily many procedures of one argument.Test your procedure on
((compose-many add1 add1 add1 add1) 3) => 7
((compose-many sqrt abs sub1 (lambda (n) (* n n))) 0.6) => 0.8
解法
跟前面的列表操作不同,这里列表的元素都是函数。题目要求定义一个函数,该函数依次从右到左将列表中的函数应用于右侧返回的结果。
- 函数实现
(define compose-many (lambda fs (cond [(null? fs) (lambda (x) x)] [else (lambda (x) ((car fs) ((apply compose-many (cdr fs)) x)))])))
- 宏实现
(define-syntax compose-many (syntax-rules () [(_) (lambda (x) x)] [(_ f1 f2 ...) (lambda (x) (f1 ((compose-many f2 ...) x)))]))
1 0
- P29 (**) Compose arbitrarily many procedures of one argument.
- The Procedures of Ping
- a complete example of using One to Many and One to One associations using MyBatis annotations
- Overview of Docker Compose
- why inverse must be setted in hibernate bidirectional association of one-to-many and many-to-many
- <many to one>和<one to many>
- <many-to-one>和<one-to-many>
- hibernate many-to-one // one-to-many
- nhibernate one to one,one to many
- one to many
- Many-to-one query
- Many-to-One映射
- hibernate many-to-one
- many-to-one
- Many-to-One映射
- JSF select One/Many
- hibernate one to many
- <many-to-one>设置
- 一起talk C栗子吧(第一百一十九回:C语言实例--线程死锁三)
- HDOJ 1217 Arbitrage (最短路 Floyd)
- Gridpanel符合条件的行有颜色
- python程序编译成exe文件
- libmad编译移植到A20
- P29 (**) Compose arbitrarily many procedures of one argument.
- 警告: A docBase inside the host appBase has been specified, and will be ignore2
- dmesg时间转换工具
- ubuntu 寝室拨号上网以及在家上网
- LeetCode24. Swap Nodes in Pairs简单到一次性通过
- 重构的七宗罪
- RecyclerView完全解析,让你从此爱上它(二十八)
- 大话设计模式-单例模式
- Python Redis数据结构服务器