全民Scheme(1):数字游戏
2024-08-29 10:26:41
刚刚看到两句话,感觉不错,分享给大家:
1.用户的问题。就是我们的问题
2.做一些用户想要的东西
(define add1
(lambda (x)
(+ 1 x))) (define sub1
(lambda (x)
(- x 1))) (add1 67)
(sub1 5)
(sub1 0) (zero? 22) (define addup
(lambda (tup)
(cond
((null? tup) 0)
(else (+ (car tup) (addup (cdr tup))))))) (addup '(3 4 5)) (define *
(lambda (x y)
(cond
((eq? 1 x) y)
(else (+ y (* (sub1 x) y)))))) (* 3 9) (define tup+
(lambda (tup1 tup2)
(cond
((null? tup1) '())
(else (cons (+ (car tup1) (car tup2)) (tup+ (cdr tup1) (cdr tup2))))))) (tup+ '(2 3 4 5) '(5 4 3 2)) (define >
(lambda (x y)
(cond
((zero? x) #f)
((zero? y) #t)
(else (> (sub1 x) (sub1 y)))))) (> 4 3)
(> 3 3)
(> 3 4) (define <
(lambda (x y)
(cond
((zero? y) #f)
((zero? x) #t)
(else (< (sub1 x) (sub1 y))))))
(< 3 3)
(< 4 3)
(< 3 4) (define =
(lambda (x y)
(cond
((> x y) #f)
((< x y) #f)
(else #t))))
(= 3 4)
(= 3 3)
(= 4 3) (define expt
(lambda (x y)
(cond
((zero? y) 1)
(else (* x (expt x (sub1 y))))))) (expt 5 3) (define /
(lambda (x y)
(cond
((< x y) 0)
(else (add1 (/ (- x y) y))))))
(/ 10 2) (define length
(lambda (lat)
(cond
((null? lat) 0)
(else (add1 (length (cdr lat)))))))
(length '(good hello)) (define pick
(lambda (n lat)
(cond
((eq? n 1) (car lat))
(else (pick (sub1 n) (cdr lat)))))) (pick 3 '(hotdogs with hot mustard)) (define no-nums
(lambda (list)
(cond
((null? list) '())
((number? (car list)) (no-nums (cdr list)))
(else (cons (car list) (no-nums (cdr list))))))) (no-nums '(5 pears 6 prunes 9 dates)) (define all-nums
(lambda (lat)
(cond
((null? lat) '())
((number? (car lat)) (cons (car lat) (all-nums (cdr lat))))
(else (all-nums (cdr lat))))))
(all-nums '(99 abc 33 mm 9 gg fuck)) (define eqlat?
(lambda (a1 a2)
(cond
((and (null? a1) (null? a2)) #t)
((and (number? (car a1)) (number? (car a2)))
(cond
((= (car a1) (car a2)) (eqlat? (cdr a1) (cdr a2)))
(else #f)))
((eq? (car a1) (car a2)) (eqlat? (cdr a1) (cdr a2)))
(else #f)))) (eqlat? '(a b c 33) '(a b c 33)) (define occur
(lambda (a lat)
(cond
((null? lat) 0)
((number? a)
(cond
((and (number? (car lat)) (= (car lat) a)) (add1 (occur a (cdr lat))))
(else (occur a (cdr lat)))))
((number? (car lat)) (occur a (cdr lat)))
((eq? a (car lat)) (add1 (occur a (cdr lat))))
(else (occur a (cdr lat))))))
(occur 'a '(a b c d e a 3 4 a))
(occur 3 '(b cd e 3 4 3 ed 3)) (define one?
(lambda (n)
(= n 1))) (one? 3)
最新文章
- Start Instance 操作详解 - 每天5分钟玩转 OpenStack(31)
- cocos2d-x 开头配置(Windows 平台)
- App.config/Web.config 中特殊字符的处理
- iOS Block浅析
- eclipse gradle 自动打包
- 1934: [Shoi2007]Vote 善意的投票 - BZOJ
- sql常识-Alias
- Jquery环境搭建前言
- MapReduce极简教程
- fiddler学习资源
- Caused by: java.sql.SQLException: Incorrect integer value: &#39;&#39; for column &#39;clientId&#39; at row 41
- Scala:集合类型Collection和迭代器
- Redis持久化之RDB
- 尽量避免把弹窗加在window上,可以考虑把弹窗封装到控制器里面
- Replica Set + sharding搭建mongodb集群
- java中 this() 和super()的作用及用法
- v2v-VMware/VSphere中虚机离线迁移至openstack平台
- linux 取消笔记本触摸键
- Nginx配置WebService、MySQL、SQL Server、ORACLE等代理
- ejabberd与XMPP
热门文章
- WCF技术解剖2-TcpTracer路由解析代码
- bzoj 1579: [Usaco2009 Feb]Revamping Trails 道路升级——分层图+dijkstra
- OpenCV 2.4.9 学习笔记(4)—— 像素类型与Templates的限制使用
- IAT Hook
- 转: 嵌入式linux下usb驱动开发方法--看完少走弯路【转】
- 【linux高级程序设计】(第十三章)Linux Socket网络编程基础 3
- springBoot Ribbon Hystrix
- 系统封装的dispatch系列代码块引起的循环引用
- Ribbon负载均衡(四)
- [BZOJ3920]Yuuna的礼物