SICP Section 2.2.1
来源:互联网 发布:iphone6s蜂窝数据快捷 编辑:程序博客网 时间:2024/06/05 07:03
Exercise 2.17
#lang racket(define (last-pair l) (if (null? (cdr l)) l (last-pair (cdr l))))
Exercise 2.18
#lang racket; (define (reverse list); (define (mid-reverse list midlist); (if (null? list); midlist; (mid-reverse (cdr list) (cons (car list) midlist)))); (mid-reverse list '()));'() can't be replaced as (list) why?;use append(define (reverse items) (if (null? items) (list) (append (reverse (cdr items)) (list (car items)))))
Exercise 2.19
#lang racket(define (cc amount coin-values) (cond ((= amount 0) 1) ((or (< amount 0) (no-more? coin-values)) 0) (else (+ (cc amount (except-first-denomination coin-values)) (cc (- amount (first-denomination coin-values)) coin-values)))))(define no-more? null?)(define except-first-denomination cdr)(define first-denomination car)(define us-coins (list 50 25 10 5 1))(cc 100 us-coins)
Exercise 2.20
#lang racket;the two number is same even-odd parity?(define (same-kind? first second) (= (remainder (- first second) 2) 0));compare the first to the rest recursely(define (same-parity first . dulp) (let ((dulpp dulp)) (define (parity first dulpp) (if (null? dulpp) (list first) (let ((comparison (car dulpp)) (rest (cdr dulpp))) (if (same-kind? first comparison) (cons first (parity comparison rest)) (parity first rest))))) (parity first dulpp)));output(same-parity 2 4 6 8 9 10)
Summarize
闭包很强大,它允许我们轻松的创造层级结构,换言之,它能够创造很多基本的或复杂的数据结构,比如序列和树。任何强有力的编程语言都会提供这种能力。
- SICP Section 2.2.1
- SICP section 2.2
- SICP section 1.1
- SICP section 1.2
- SICP Section 2.3.2
- SICP Section 2.1.3
- SICP Section 2.1.4
- sicp-1
- sicp 2.2 习题
- sicp习题2.2
- SICP 2.2 嵌套映射
- SICP-2.2-String
- SICP学习笔记(1)
- SICP读书笔记-1
- SICP学习笔记(1):
- SICP ex 1-27
- sicp
- SICP
- POJ 2960
- 用word中的正则表达式批量删除不想要的东西
- java插入法排序学习笔记
- 不同浏览器读取XML问题
- 【leetcode】4Sum
- SICP Section 2.2.1
- Android 开发小技巧(1)
- Cookie的应用
- stucts 页面跳转
- 暗黑破坏神3难度的钥匙去哪里打?
- 改错(1)
- Debian Wirelwss Network Howto
- cf256e
- 接口继承规则